11월 27일
프로그래밍/C/C++ 2006. 11. 28. 10:02 |#include
#include
//===============================================================
//11-5
//===============================================================
/*
int main()
{
FILE* fptr;
char ch;
long int offset, last;
fptr = fopen("test.txt", "r");
if(fptr == NULL)
{
printf("error");
exit(1);
}
fseek(fptr, 0L, SEEK_END);
last = ftell(fptr);
for(offset = 0; offset < last; ++offset)
{
fseek(fptr, offset, SEEK_SET);//앞에서부터 출력
//fseek(fptr, -offset, SEEK_END);//뒤에서 부터 출력
ch = getc(fptr);
switch(ch)
{
case 'n': printf("LF : ");
break;
case EOF : printf("EOF : ");
break;
default: printf("%c :", ch );
}
}
fclose(fptr);
return 0;
}
*/
//===========================================================
//11-6
//===========================================================
int main()
{
FILE* fptr;
char ch;
fptr = fopen("test.txt", "r");
if(fptr == NULL)
{
printf("Error");
exit(1);
}
fseek(fptr, 0L, SEEK_SET);
ch = getc(fptr);
printf("%c", ch);
return 0;
}
//12장=========================
#include
/*
int main()
{
enum color {red, green = 4, yellow};
//4를 넣으면 yellow는 5가 된다
enum color crayon = red;
printf("nThe color is %dn", crayon);
printf("Enter a value: ");
scanf("%d", &crayon);
if(crayon == red)
printf("The crayon is red.n");
else if(crayon == green)
printf("The crayon is green.n");
else if(crayon == yellow)
printf("The crayon is yellow.n");
else
printf("The color is not defined.n");
return 0;
}
*/
//입력에 yellow를 쓰면 red가 나온다...집접 타이핑은 안된다...
int main()
{
int hour, rate;
hour = 50;
rate = (hour>40)?1:2;
printf("The rate is: %d", rate);
return 0;
}