0

Hello

can anyone help me with the following
The below will actually display the Name found part, even though no name actually exists and its just blank, how do i get round this, the string name will contain blanks, but i need to check if blank, then treat as blank.

char name[80]
   int len;
 
   strcpy(name, "                       " );
   len=strlen(name);
 
   if (len == 0 )
   {
 
        printf("No name....\n" );
   }
   else
   {
        printf("Name found...\n" );
   }

Edited by Nick Evan: n/a

2
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by Nick Evan
0

But this is setting the variable length to 0 bytes

what happens if there is actually a real values in name like

name=[80];

strcpy(name, "CHRISXHSHSHSHSH" );

0

excuse me, want I meant was:

if (name[0] == ' ')
{
    printf("No name....\n" );
}

I was busy doing a prog in basic so I messed up the syntax :rolleyes:

0

What compiler are you using, because I use VS2005pro and it works fine with me:

int main(int argc, char *argv[])
{
 
char name[80];
 
strcpy(name, " " );
 
if (name[0] == ' ')
{
printf("No name....\n" );
}
else
{
printf("Name found...\n" );
}
getchar();
getchar();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.