hi.another post by me.ehehe
pls check this code.i wonder how this would work:
this program asks for the last and first name of the user.and at the same time it must separate the first names of the user.for example, the name of the user is juan miguel bautista. it will store (and print) the names juan and miguel in an n-dimensional array inside a structure.
hope you will help me with this.:D
#include <stdio.h>
#include <string.h>
#define MAXLEN 15
#define TEMP_MAX 225
typedef struct name {
char lastname [MAXLEN];
char firstname [MAXLEN][MAXLEN];
} name_t;
int main(void)
{
char firstname [TEMP_MAX];
char space[1] = {' '};
name name_t;
int i=0, j=0, k=0, l=1;
puts("");
puts("\t\tThe Sorting Hat");
puts("");
printf("\tYour Last Name? ");
fgets(name_t.lastname, sizeof(name_t.lastname), stdin);
name_t.lastname[strlen(name_t.lastname)-1] = '\0';
printf("\tYour First Name? ");
fgets(firstname, sizeof(firstname), stdin);
firstname[strlen(firstname)-1] = '\0';
while(i!=MAXLEN){
if(firstname[i] != space[0]){
name_t.firstname[j][k] = firstname[i];
i++;
k++;
}
while(firstname[i] == space[0]){
i++;
if(firstname[i] != space[0]){
name_t.firstname[j][k] = firstname[i];
i++;
k++;
j++;
}
}
}
printf("Interesting. You have %d names:\n", j+1);
while(l!=j){
printf("%d. %s\n",l, name_t.firstname[j]);
l++;
}
return 0;
}