Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int main(int argc, char *argv[])
- {
- FILE *fp;
- char str[255];
- int c;
- if(argc!=2)
- {
- printf("Specify file name.\n");
- exit(1);
- }
- while(100)
- {
- printf("Which mode?\n1. Write to file\n2. Read from file\n3. Append to file\n");
- printf("Enter choice:");
- scanf("%d", &c);
- if(c==1)
- {
- if((fp=fopen(argv[1], "w"))==NULL)
- {
- printf("The file does not exist!\n");
- exit(1);
- }
- while(*str!='\n')
- {
- fflush(stdin);
- printf(":");
- gets(str);
- strcat(str, "\n");
- if(*str!='\n')
- fputs(str, fp);
- }
- fclose(fp);
- }
- if(c==2)
- {
- if((fp=fopen(argv[1], "r"))==NULL)
- {
- printf("The file does not exist.\n");
- exit(1);
- }
- while(!feof(fp))
- {
- fgets(str, 254, fp);
- if(!feof(fp))
- printf(str);
- }
- fclose(fp);
- }
- if(c==3)
- {
- if((fp=fopen(argv[1], "a"))==NULL)
- {
- printf("The file does not exist!\n");
- exit(1);
- }
- while(*str!='\n')
- {
- fflush(stdin);
- printf(":");
- gets(str);
- strcat(str, "\n");
- if(*str!='\n')
- fputs(str, fp);
- }
- fclose(fp);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment