how can i copy 5 fields into 1variable
i have 5 variables. after user input all data in those variables[characters]. then i have to put all data from 5 variables into 1 variable which goes to 1 array and i have to repeat untill the user has finished entering dat.
manuindex[i]=code,name,address,contact
how can i do this thing
this is my try
Code:
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
struct Manufacturer
{
char manuindex[100,62], code[6],nam[16], address[21],contact[11];
int i;
//bool pass;
};
main(void)
{
struct Manufacturer m;
puts("Enter code"); //
gets(m.code);
//fflush(stdin);
for(m.i=0;m.i<100;m.i++);
{
while (strlen(m.code)>0)
{
puts("Enter name:");
gets(m.name);
puts("Enter address");
gets(m.address);
puts("Enter Contact");
gets(m.contact);
strcpy(m.manuindex[m.i],m.code);
strcat(m.manuindex,m.name);
strcat(m.manuindex,m.address);
strcat(m.manuindex,m.contact);
puts("Enter code:");
gets(m.code);
}
}
printf(m.manuindex[1]); // just checking data
}
Thanks
Re: how can i copy 5 fields into 1variable
>char manuindex[100,62],
This bit is a syntax error. If you want a 2d array, do so like this:
char manuindex[100][62],
>nam[16],
Should this say: name[16] ?
>//fflush(stdin);
Leave that one commented out, it's undefined so not guaranteed to work on all systems.
>gets()
is very bad, it does no bounds checking (search board for more information). Try using fgets() instead.
>strcpy() and strcat()
This doesn't do bounds checking, try using strncpy() and strncat() to keep your prog safe.
Lastly, add return(0); to the end of the main() function.
The program won't compile with those syntax errors. If you're new to C, try compiling it anyway so that you get used to the error messages that the compiler comes back with. That way you'll be able to fix the simple errors yourself.;)