Hey guys - Ive been looking through the archives but have not found what I am looking for. What I want to do is have a mailing list - that is a maximum of 10 entries long (structure array) - It compiles but gives me some warnings in gcc which I will post below.
---------------------------------
discostu@Darkstar:~/c_code/12$ pico 1.c
discostu@Darkstar:~/c_code/12$ gcc -o 1 1.c
1.c: In function `main':
1.c:18: warning: useless keyword or type name in empty declaration
1.c:29: warning: passing arg 1 of `fgets' makes pointer from integer without a cast
1.c:40: parse error before `{'
-----------------------------------------
when I enter info in it will give a segmentation error once all the fields are filled out for the first time.
Code:
/* This program will develop a mailing list that will do no more than be practice for structures */
#include <stdio.h>
int main ()
{
typedef struct list {
char name[60];
char address[60];
char city[30];
char state[3];
long int zip;
};
struct list mailing[10];
int counter = 0;
char another;
int count = 0;
/*Looping for input */
while (1) {
if (count > 0) {
puts("Do you want to add another field? (y/n): "); /* Checking to see if they want to add another field*/
fgets(another, sizeof(another), stdin);
if ((another == 'y') || (count > 10)) {
break;
}
}
printf("Enter in the name (last, first): ");
fgets(mailing[count].name, sizeof(60), stdin);
printf("Enter in the address: ");
fgets(mailing[count].address, sizeof(60), stdin);
printf("Enter the city: ");
fgets(mailing[count].city, sizeof{30), stdin);
printf("Enter State: ");
fgets(mailing[count].state, sizeof(3), stdin);
printf("Enter Zip: ");
scanf("%d", mailing[count].zip);
++count;
}
/* Loop until where counter left off last time and print data to screen */
for (counter; counter < count; ++counter) {
printf("%s\n", mailing[counter].name);
printf("%s\n", mailing[counter].address);
printf("%s\n", mailing[counter].city);
printf("%c, ", mailing[counter].state);
printf("%d\n", mailing[counter].zip);
printf("\n");
}
return(0);
}
FYI - this isn't homework