Function that assigns names to a struct using strtok I worked around using strtok function so to assign first name and last name to a struct PERSONNE from a char *names[] array. It was not possible to directly modify the *names[] using strtok since it was throwing an exception.

This code works fine but the last loop shows a lot of '\n' until it reaches 10. I am unable to set the unused data in p1 to NULL. Is it bad practice to not set unused structure data to NULL?

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;time.h&gt;

#define u_short             unsigned short
#define u_int               unsigned int

#define bool                int
#define true                1
#define false               0

#define MAX                 10

typedef struct PERSONNE
{
    int id;
    char nom[MAX];
    char prenom[MAX];
}personne, *p_personne;

char *names[]={
                "HARRY JANDU",
                "LIBNI MACTAVISH",
                "DIMPLE CHOWDARI",
                "PRIYA MOHAN",
                NULL
            };

int main(void)
{
    int i, j;
    personne p1[10];
    memset(&amp;p1, 0, sizeof(p1));       // doesn't set to 0
    for( i=0; i&lt;sizeof(names); i++ )
    {
        if( names[i]==NULL )break;
        char *temp=NULL, *pch=NULL;
        temp=(char*)malloc(strlen(names[i]));
        strcpy(temp, names[i]);
        pch=strtok(temp, " ");
        strcpy(p1[i].prenom, pch);
        while( pch!=NULL )
        {
            strcpy(p1[i].nom, pch);
            pch=strtok(NULL, " ");
        }
    }

    printf("FIRST NAME\tLastName\n");
//  printf("%d\n", p1[0]);
    for( i=0; i&lt;10; i++ )
    {
        if( p1[i].nom==0 )break;
        printf("%s\t\t%s\n", p1[i].prenom, p1[i].nom);
    }

    return 0;
}
I see some things that may help you improve your code.

Use whitespace to improve readability

Lines like this:

for( i=0; i&lt;sizeof(names); i++ )


become easier to read with a bit more whitespace:

for (i = 0; i &lt; sizeof(names); i++) 


Prefer ++i to i++ in loops

There is not a big difference for most uses, but if you don't need to save the pre-incremented value, make it simple for both the reader and the compiler and say ++i.  This also will help when you start using C++ iterators which often only implement the prefix ++ operator.

Declare the loop exit condition at the top

The code currently contains these lines:

for (i = 0; i &lt; sizeof(names); i++) {
    if (names[i] == NULL)
        break;


So the for loop claims that the loop exits when i &gt;= sizeof(names) but the following line says we exit when names[i] == NULL.  In this program, only latter is actually used, so the loop should be written to reflect that:

for (i = 0; names[i] != NULL; i++) {


Similarly, the printing loop can be simplified:

for (i = 0; p1[i].prenom[0]; ++i) {
    printf("%s\t\t%s\n", p1[i].prenom, p1[i].nom);
}


Eliminate unused variables

Unused variables are a sign of poor code quality, so eliminating them should be a priority.  In this code, j is defined but not used. Your compiler is probably also smart enough to tell you that, if you ask it to do so.  Also, the code includes a number of unused #defines, one unused typedef and one unused struct member, all of which just add to clutter in the code.

Use only required #includes

The code has #include &lt;time.h&gt; but nothing from that header is used.  This clutters the code and makes it more difficult to read and understand.  Only include files that are actually needed.

Use const where practical

The current code does not  modify the names array, and so it should be declared const:

const char const *names[] = {


Use stdbool

Instead of defining your own values for true and false, you might consider instead using #include &lt;stdbool.h&gt; which defines true and false.  However, in this program, neither is used.

Free memory that you allocate

This program leaks memory because you have allocated space using malloc but never released with free.  That's bad practice.  

Eliminate useless code

The code currently contains this loop:

while (pch != NULL) {
    strcpy(p1[i].nom, pch);
    pch = strtok(NULL, " ");
}


This has the effect of copying each word in the name and only saving the last one which is not very efficient.  See the next suggestion for a more efficient means.

Use the appropriate library function

Instead of copying the string and using strtok, I'd recommend that the code should use strchr.

for (i = 0; names[i] != NULL; i++) {
    char *pch = strchr(names[i], ' ');
    if (pch == NULL || pch-names[i] &gt; MAX) {
        strncpy(p1[i].prenom, names[i], MAX);
    } else {
        strncpy(p1[i].prenom, names[i], pch-names[i]);
        strncpy(p1[i].nom, pch, MAX);
    }
    p1[i].nom[MAX-1] = '\0';
    p1[i].prenom[MAX-1] = '\0';
}


Note too, that this code uses the safer strncpy and also assures that each string is properly terminated with '\0'.

Make sure your data structures are big enough

With only 10 characters allocated for both nom and prenom, many names simply won't fit. "Ludwig van Beethoven" is one such example.

Eliminate return 0 at the end of main

Since C99, the compiler automatically generates the code corresponding to return 0 at the end of main so there is no need to explicitly write it.