Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int main(int argc, char *argv[])
- {
- FILE *fp;
- char str[255], *p;
- int i;
- if(argc!=2)
- {
- printf("Specify file name.\n");
- exit(1);
- }
- if((fp=fopen(argv[1], "w"))==NULL)
- {
- printf("Can't open file.\n");
- exit(1);
- }
- printf("Enter text:");
- gets(str);
- p=str;
- while(*p)
- {
- if(fputc(*p, fp)==EOF)
- {
- printf("Error writing file.\n");
- exit(1);
- }
- p++;
- }
- fclose(fp);
- if((fp=fopen(argv[1], "r"))==NULL)
- {
- printf("Can't open file.\n");
- exit(1);
- }
- for(;;)
- {
- i=fgetc(fp);
- if(i==EOF)
- break;
- putchar(i);
- }
- fclose(fp);
- return 0;
- }
Add Comment
Please, Sign In to add comment