#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char *str = (char*)malloc(100);
//char string[] = "this is a test";
if( (fp=fopen("file.txt", "a+")) == NULL)
{
printf("open file.txt failed!\n");
exit(0);
}
//fwrite(string, strlen(string), 1, fp);
//fseek(fp, 0, SEEK_SET);
while(!feof(fp))
fgets(str, 100, fp); //?
fputs(str, stdout);
printf("%s", str);
//fflush(fp);
while(*str)
{
char ch = *str;
if(ch>='a' && ch<='z')
*str = ch - 32;
fputc(*str, fp);
str++;
}
fclose(fp);
return 0;
#include <string.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char *str = (char*)malloc(100);
//char string[] = "this is a test";
if( (fp=fopen("file.txt", "a+")) == NULL)
{
printf("open file.txt failed!\n");
exit(0);
}
//fwrite(string, strlen(string), 1, fp);
//fseek(fp, 0, SEEK_SET);
while(!feof(fp))
fgets(str, 100, fp); //?
fputs(str, stdout);
printf("%s", str);
//fflush(fp);
while(*str)
{
char ch = *str;
if(ch>='a' && ch<='z')
*str = ch - 32;
fputc(*str, fp);
str++;
}
fclose(fp);
return 0;
}
file.txt:
this is a test