/* Read text file */
#include<stdio.h>
int main()
{
FILE *fp;
int ch;
fp=fopen("myfile.txt","r");
if(fp==NULL)
{
printf("Can't find the source file.");
return 1;
}
while(1)
{
ch=fgetc(fp);
if(feof(fp)) break;
printf("%c",ch);
}
fclose(fp);
return 0;
}
use int ch instead of char ch
ReplyDeletehttp://c-faq.com/stdio/getcharc.html
#include
ReplyDeleteint
main(void)
{
FILE *fp;
int c;
fp = fopen("myfile.txt", "r");
if (!fp)
{
fprintf(stderr, "cannot open file to read\n");
return 1;
}
while ((c = getc(fp)) != EOF)
putchar(c);
fclose(fp);
return 0;
}
i really like that C tutorials for beginners
ReplyDeleteHTML is the canvas of the web, providing a simple yet powerful way to structure and present content, allowing creativity and functionality to flourish online! click here for more information
ReplyDelete