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;
	
}

name_t on line 16 overrides the name_t typedef on line 10. Bad idea.

line 15 could be declared as simply char space = ' '; . No need for the array syntax.

I fail to see why you need first_name to be a two dimensional array of 255 characters each dimension! That's enough for 255 names each name 255 characters long. The world's longest name is only 13 words.

BTW the longest name in the world is "Captain Fantastic Faster Than Superman Spiderman Batman Wolverine Hulk And The Flash Combined. "

According to 1978 Book of World Records the longest sir name was 590 characters.

commented: Awesome trivia! +2
commented: The trivia is what hooked me. Lol +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.