Thread: searching ><

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    searching ><

    typedef struct person{
    char code[20];
    char name[100];
    struct person *next;
    } ListPerson;

    typedef ListPerson *PersonPtr;


    hi , i have a linked list structure like above.
    code stores a 10 digits numbers
    ie 1234567891

    how can i only extract the first two digits of code, ie , in this case 12

    i tried this

    void searchCode(PersonPtr list,char cmd[20]){

    PersonPtr tmp;
    char command[MAXCODE];
    int i;

    for(tmp=list;tmp!=NULL;tmp=tmp->next){
    for(i=0;i<2;i++){
    command[i] = tmp->code[i];


    if(strcmp(command,cmd)==0){
    printf("%s,%s",tmp->ode,tmp->name)
    return;
    }
    }


    but it doesn't work ><
    can someone help me ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use....
    if ( strncmp(tmp->code,cmd,2) == 0 ) {
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Searching and matching strings: segmentation fault
    By Smola in forum C Programming
    Replies: 18
    Last Post: 07-11-2005, 12:25 AM