С Читання

2075 / C / Читання

 

FILE *fp;
char str[50];
char* filename = "1.txt";
fopen_s(&fp, filename, "r");

if (fp == NULL) {
  printf("Could not open file %s", filename);
  return 1;
}

while (fgets(str, 50, fp) != NULL) 
{
  cout << atoi(str) << endl;
}

fclose(fp);


 
 
FILE *fp;

if ((fp=fopen("test", "rb+")) == NULL) 
{
  printf ("Cannot open file.\n");
  exit(1);
}