fscanf reads incorrect value ? -Xcode

此生再无相见时 提交于 2019-12-24 07:35:04

问题


I've placed File.rtf in the directory library/Developer/Xcode/DerivedData/Test(projectname)/Build/Products/Debug and the code seems to open it but prints out the wrong output.The output is 1606422622 for any integer value in the file.

Going through the solutions of question similar to mine ,the answers were to get the input file in the right directory.I think I've done that but I just can't get the correct output.

Desperate for help.Thanks.

int main()
{
  int b;
  FILE *fp;
  fp=fopen("File.rtf","r");
  if (fp == NULL) {
    printf( "File doesn't exist!\n");
  }
  fscanf(fp,"%i",&b);
  printf("%i\n",b);

  fclose(fp);  
}

回答1:


Looks like you are trying to read a RTF formatted file. Try saving the file as a 'plain text file' in TextEdit. (with extension .txt)



来源:https://stackoverflow.com/questions/15823757/fscanf-reads-incorrect-value-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!