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

Pages: 1-

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 6:44

bump.

Name: Anonymous 2009-02-25 6:47


Print No matches n.

Name: Anonymous 2009-02-25 7:04

help?

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.

Name: Anonymous 2009-02-25 7:17

>>5

not trolled, I tried " and '
wasn't sure which was to be used.
like I said. newfag.

Name: Anonymous 2009-02-25 7:21

int strcmp ( const char *s1, const char *s2 );

^-- this is the way it's used?

I'd initialize ut first, then later use strcmp to check if my inputted string matched my pre-determined one?

Name: Anonymous 2009-02-25 7:51

strcmp(whoru[10], "namea") <-- this is wrong, I know.

but how IS it used then?

Name: Anonymous 2009-03-06 7:39

Whoru namea or nameb.

Name: Anonymous 2009-03-06 11:23


Whoru namea or nameb?

Name: Anonymous 2010-12-09 13:37


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