Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char ch[100], chr[100];
- FILE* fpw, * fpr;
- fpw = fopen("D:\\prgfiles\\lab10C.txt", "a");
- if (fpw == NULL)
- {
- printf("Error");
- exit(1);
- }
- printf("Enter another string:");
- gets(ch);
- fputs(ch, fpw);
- fclose(fpw);
- if ((fpr = fopen("D:\\prgfiles\\lab10C.txt", "r")) == NULL) //open read and compare
- {
- printf("Error! opening file");
- return(1);
- }
- while (1)
- {
- if (fgets(chr, strlen(chr), fpr) == NULL)
- break;
- }
- printf("\nAnd this is the character read from the file = %s \n", chr);
- fclose(fpr);
- return 0;
- }
- /*
- Enter another string:
- And this is the character read from the file = how are you?Second string
- */
- /*
- Enter another string:
- And this is the character read from the file = how are you?Second string third one
- */
- =====================================================================================================================================================================================================================================================================================================================================================================================================================
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- struct Friend {
- char firstname[20];
- char lastname[20];
- int streetno;
- char street[20];
- char city[20];
- };
- int main()
- {
- FILE* fpw, * fpr;
- struct Friend b[3];
- int i;
- fpw = fopen("D:\\prgfiles\\lab10E.txt", "wb");
- if (fpw == NULL)
- {
- printf("\ncannot open file\n");
- exit(1);
- }
- printf("\nEnter 3 friends details\n");
- for (i = 0; i < 3; i++) {
- printf("\nEnter first name of friend number %d: ", i + 1);
- fflush(stdin);
- gets(b[i].firstname);
- printf("\nEnter last name of friend number %d: ", i + 1);
- fflush(stdin);
- gets(b[i].lastname);
- printf("\nEnter street number of friend number %d: ", i + 1);
- fflush(stdin);
- scanf("%d", &b[i].streetno);
- getchar();
- printf("\nEnter street name of friend number %d: ", i + 1);
- fflush(stdin);
- gets(b[i].street);
- printf("\nEnter city name of friend number %d: ", i + 1);
- fflush(stdin);
- gets(b[i].city);
- }
- fwrite(b, sizeof(struct Friend), 3, fpw);
- printf("\n!!!!DATA HAS BEM STORAGED!!!!");
- fclose(fpw);
- fpr = fopen("D:\\prgfiles\\lab10E.txt", "rb");
- if (fpr == NULL)
- {
- printf("\ncannot open file\n");
- exit(1);
- }
- fread(b, sizeof(struct Friend), 3, fpr);
- printf("\n Friends Details...\n");
- for (i = 0; i < 3; i++)
- {
- printf("\nfriend #%d:\t%s %s,\t%d %s,\t%s \n", i + 1, b[i].firstname, b[i].lastname, b[i].streetno, b[i].street, b[i].city);
- fclose(fpr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement