+1 for posting your code
-1 for failing to use [code][/code] tags. Read the following links.
Forum guidelines.
Posting code? Read this first!
Homework policy. Not that this necessarily applies here, but it's good to read anyway.
Here's what your code should look like:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
typedef struct{
int number;
} Entry;
int main(int argc, const char * argv[])
{
char filename[80];
FILE *fp;
int rows;
input = 0;
while(!input){
printf("\nEnter the name of the file: ");
scanf("%s", filename);
if((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Unable to open %s\n", filename);
printf("Please make sure the specified file exists.");
}
else input = 1;
}
if(fscanf(fp, "%d", &rows) != 1) {
fprintf(stderr, "Error reading from %s\n", filename);
exit(-2);
}
printf("\nNumber);
for(i = 0; i < rows; i++)
{
fscanf(fp, "%d", &entries[i].number);
printf("%d", entries[i].number);
}
res = fclose(fp);
if(res == 0) {
printf("File closed\n");
}
else
{
printf("Unable to close file\n");
}
fp = NULL;
verify=0;
while(!verify){
printf("\nContinue? (y = yes, n = no):");
scanf(" %c", &repeat);
if(repeat == 'y' | repeat == 'n')
verify=1;
else printf("\nIncorrect response.");
}
return 0;
}
Make sure you use an editor with syntax highlighting. You'll notice that here, you forgot a " on line 34 (maybe a copy-paste error).
Your code as posted can't hang because it wont even compile. Then compile with errors turned all the way up:
Code:
$ make foo
gcc -g -Wall -std=c99 -o foo foo.c -lpthread -lm -lpq
foo.c: In function ‘main’:
foo.c:18:5: error: ‘input’ undeclared (first use in this function)
foo.c:18:5: note: each undeclared identifier is reported only once for each function it appears in
foo.c:36:9: error: ‘i’ undeclared (first use in this function)
foo.c:38:27: error: ‘entries’ undeclared (first use in this function)
foo.c:42:5: error: ‘res’ undeclared (first use in this function)
foo.c:53:5: error: ‘verify’ undeclared (first use in this function)
foo.c:56:23: error: ‘repeat’ undeclared (first use in this function)
All those are basic errors -- undefined variables. Please provide their definitions so we can compile your code and help you with your problem.
Also, give a clearer description of what the code should do. What do you mean by print them each in a different column. Different how? How do you determine which column to print them in?
[EDIT]
Oh yeah, and don't #include <conio.h>. It's an outdated header that is Windows-specific, and you aren't actually using any features from that header anyway, so it's pointless to have it in there.
[/EDIT]