Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C newfag

Name: Anonymous 2009-02-25 6:36

Trying to write something to compare names. Check to see which you've entered (one of several 'users') then spout some printf shit or change integers depending on the given name.

Code is

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   
    char whoru[10];
  
    printf( "whoru? namea or nameb? \n" );
    fgets( whoru, 10, stdin );
    if (
        whoru[10] == 'namea'
        ) printf("A");
    else if (
             whoru[10] == 'nameb'
             ) printf("B");
    else
             printf("Whoru?");
            
    getchar();
    return 0;
}

Will take a verbal beating if anyone can help me out.

I'm new + trawling C tuts + google for anything I could find, such as fgets, I might be using it wrong, I do not know.

Name: Anonymous 2009-02-25 7:09

Use strcmp(), as comparing something to a string constant makes no sense in C.
whoru[10] == 'nameb'
Apostrophes.
I think I just got trolled.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List