Hi everyone im getting real problems getting a file reading program to work. Here is the file reading function, if i comment it out, the program runs fine so I know this is the "offending" function. Ive included the errors too. If anyone is able to spot whats making it error your help would be much appreciated. i picked up some sloppy programming habbits so maybe there is some better practice things also which id like to improve hopefully so any constructive criticism will be appreciated. thankyou
Code:{ //------------------------------------------------------------< Extracting Data from textfile and putting them in order > int loop; int numberOfReadings; int signalOutput; int flag; int column1; float column2; float temperatureArray[10]; srand(time(NULL)); FILE *fp; printf("\n\n The sensor readings and their corresponding temperatures:\n"); fp = fopen("LOOKUP.txt", "r"); for(loop=0; loop<numberOfReadings; loop++) { signalOutput = (int)(rand()%15); for(flag=0; flag=1; 0) { fscanf(fp, "%i %f",&column1, &column2); if ( signalOutput > column1 ) { temperatureArray[loop] = column2; flag = 1; printf("\n se %i = %f", signalOutput, temperatureArray[loop]); } } } fclose(fp); }
1>------ Build started: Project: Assignment 3, Configuration: Debug Win32 ------
1> Assignment 3.c
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(34): warning C4013: 'welcome' undefined; assuming extern returning int
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(35): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(76): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(85): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(25): warning C4101: 'inputError' : unreferenced local variable
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(28): warning C4101: 'pointers' : unreferenced local variable
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(127): warning C4244: 'function' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(128): error C2275: 'FILE' : illegal use of this type as an expression
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(66) : see declaration of 'FILE'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(128): error C2065: 'fp' : undeclared identifier
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(132): error C2065: 'fp' : undeclared identifier
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(132): warning C4047: '=' : 'int' differs in levels of indirection from 'FILE *'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(140): error C2065: 'fp' : undeclared identifier
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(140): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(140): warning C4024: 'fscanf' : different types for formal and actual parameter 1
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(152): error C2065: 'fp' : undeclared identifier
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(152): warning C4047: 'function' : 'FILE *' differs in levels of indirection from 'int'
1>c:\users\david baratheon\documents\visual studio 2010\projects\assignment 3\assignment 3\assignment 3.c(152): warning C4024: 'fclose' : different types for formal and actual parameter 1
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========