main(){{}{}{}
{;;;;;;}
{ }
{ }
{ }
{ }
{ }
{;;;;;;}
{;;;;;;}
{ }
{ }
{ }
{ }
{ }
{;;;;;;}}
2010年12月31日 星期五
2010年12月29日 星期三
Cannot open that file
Cannot open that file.
int main()
{
char filename[80];
FILE *fp;
printf("input file name: ");
fgets(filename, 79, stdin);
fp = fopen(filename, "r");
assert(fp != NULL);
fclose(fp);
}
C:\SVN\book\C>ls -l fgets.c -rw-rw-rw- 1 user group 225 Dec 29 17:23 fgets.c C:\SVN\book\C>a.exe input file name: fgets.c Assertion failed: fp != NULL, file fgets.c, line 10
2010年12月27日 星期一
變數靈異事件
#include <stdio.h>
#include <string.h>
int main(void)
{
char source[] = "This is a string.";
int i = 5;
char destination[4];
strcpy(destination, source);
printf("i is %d\n", i);
printf("source is [%s]\n", source);
printf("destination is [%s]\n", destination);
return 0;
}
The output.i is 544434464 source is [a string.] destination is [This is a string.]
CSIE rules!
struct csie {
char c;
short s;
int i;
double e;
};
struct ceis {
char c;
double e;
int i;
short s;
};
int main(void)
{
printf("csie = %d\n", sizeof(struct csie));
printf("ceis = %d\n", sizeof(struct ceis));
return 0;
}
The output.csie = 16 ceis = 24
2010年12月26日 星期日
7 * 7 = 19
The output is 19, not 49.
#include <stdio.h>
#define square(x) (x * x)
int main()
{
int i = 3;
int j = 4;
printf("%d\n", square(i + j));
}
#include <stdio.h>
#define square(x) (x * x)
int main()
{
int i = 3;
int j = 4;
printf("%d\n", square(i + j));
}
為何不用 char c 寫檔
有朋友問到之前 255 and 256 的例子為何不用 char c 寫檔.
如果你的膽子和硬碟都很大, 請自行嘗試. 後果P老師概不負責.
#include <stdio.h>
int main(void)
{
FILE *fp;
char c;
fp = fopen("file", "wb");
for (c = 0; c < 256; c++)
fputc(c, fp);
fclose(fp);
return 0;
}
如果你的膽子和硬碟都很大, 請自行嘗試. 後果P老師概不負責.
#include <stdio.h>
int main(void)
{
FILE *fp;
char c;
fp = fopen("file", "wb");
for (c = 0; c < 256; c++)
fputc(c, fp);
fclose(fp);
return 0;
}
訂閱:
意見 (Atom)