Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char * filename = "D://bsuir/oaip/2_1/c/2_1/bin/Debug/input.txt";
- FILE *file;
- char name[20];
- int nums[3][3];
- if((file = fopen(filename, "r")) == NULL)
- {
- perror("Error occured while opening file");
- return 1;
- }
- int i, j;
- for(i = 0; i < 3; i++){
- for(j = 0; j < 3; j++){
- fscanf(file, "%d", &nums[i][j]);
- printf("%d ", nums[i][j]);
- }
- printf("\n");
- }
- //printf("%s %d\n", name, age);
- //}
- fclose(file);
- /*
- char * message = "Hello \n world!\n An apple a day keeps the doctor away";
- char * filename = "D://bsuir/oaip/2_1/c/2_1/bin/Debug/output.txt";
- char cc[256];
- FILE *fp;
- // запись в файл
- if((fp= fopen(filename, "w"))==NULL)
- {
- perror("Error occured while opening file");
- return 1;
- }
- // записываем строку
- fputs(message, fp);
- fclose(fp);
- // чтение из файла
- if((fp= fopen(filename, "r"))==NULL)
- {
- perror("Error occured while opening file");
- return 1;
- }
- // пока не дойдем до конца, считываем по 256 байт
- while((fgets(cc, 256, fp))!=NULL)
- {
- printf("%s", cc);
- }
- fclose(fp);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement