![]() |
| ||
| help with program using structures and printing to screen This code is suppose to read from an inputed file and then fill and array and sort the student records with in that file. Im having alot of trouble debugging myself and this program is due with in two days. the input will look like lastname, firstname grade ssn birthday date of first attendence my main problem is mostly the coding from 46 to 78 i know i have mistakes but im a pretty new to c programming. thanks david #include <stdio.h> |
| ||
| Re: help with program using structures and printing to screen Starting somewhere for no particular reason: arr[][STR_SIZE]; //is this legal for me to use?It would be legal if you would have initialized arr, however since you didn't the compiler doesn't know how much space must set apart for arr. arr[][STR_SIZE] = { "One", "Two", "Three" }; /* This would be OK */ typedef struct Why to create a whole new data type structure for just one element inside? int fillArray(FILE *inf, arr[]); Not quite sure why you need to pass a pointer to a file handle. You are not doing anything with it inside the function. arr is an array of arrays. You are just passing it as an array or string. The easiest way is to prototype the multidimensional array the same way you declared if arr[][STR_SIZE] then type_data function_name( arr[][STR_SIZE] ); if arr[MAX][MAX] then type_data function_name( arr[][MAX] ); scanf("%s", arr[i]); // is this the right way to fill an array or am i really wrong?If you would have pass arr the proper way it would have a chance of being correct, other than scanf is not a good way of obtaining string data from user.Search for fgets() |
| All times are GMT -4. The time now is 4:16 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC