I am getting weird output while running code written below on Xcode. The program simply reads integers from a file given like command line argument, and outputs array of those integers.
That is the result that I get:
"0 Program ended with exit code: 0"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
FILE* file;
file = fopen(argv[1], "r");
if (!file) {
printf("error occured!! make sure right file is provided");
}
else{
int i = 0;
// int value;
int array[atoi(argv[2])];
while (!feof(file)) {
fscanf(file, "%d", &array[i]);
printf("%d ", array[i]);
i++;
}
}
return 0;
}
However, if I run same code from terminal it outputs expected result:
I guess the problem might be the arguments that I provided in Xcode, but I can't figure out what precisely.
Update: My input.txt file contains following: "1 2 3 4 5"
Update: SOLVED Seems there is a bug in Xcode after last update. When Files names are added into the arguments section..it does not create them in debug folder. I manually created file "input.txt" in the following folder:/Users/name/Library/Developer/Xcode/DerivedData/percentile-ecpffkfxacqgpggopnguhvlicvtt/Build/Products/Debug (it could be accessed by selecting 'Show In Finder' from executable name in the 'Products' group in the Xcode Project Navigator) and it worked.