/stores and retrieves data for two secret asgents

#include<stdio.h>

void main ()
{

struct personnel {
char name [30];
int agnumb; int agent;
};

struct personnel agent1;
struct personnel agent2;
char numstr[81];

printf("\nagent 1.)\nEnter name:");
printf("Enter agent number (3 digits): ");
gets(numstr);
agent1.agnumb=atoi(numstr);
gets(agent2.name);
printf("Enter agent number (3 digits);");
gets(numstr);
agent2.agnumb=atoi(numstr);

printf("\nList of agents:\n);
printf("Agent number: %03d\n", agent1.agnumb);
printf("Name: %s\n", agent2.name);
printf(Agent number: %3d \n", agent2.agnumb);
}

i would also like to use arrays so that the stucture can store and retrieve data of 20 agents. pls hel

whats the error that you're getting??

for array of structure say

personnel arr[20];
arr[0].name = "blah";
..
..
arr[1].name = "blah";

and so on and so forth. you can put this in a loop to take 20 inputs

A few things are wrong:

- It's int main() not void main()
- If you want to use atoi, you'll have to include <stdlib.h>
- Don't use gets(), you don't need to take in a string when you want an int

You have an error is this line:

printf("\nList of agents:\n);

There's a quote (") missing.

In this line the same problem:

printf(Agent number: %3d \n", agent2.agnumb);

If you had used code-tags when posting you would have seen it yourself.

Niek

This article has been dead for over six months. Start a new discussion instead.