CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2013
    Posts
    30

    [RESOLVED] strcmp on Linked List data and string constants?

    Was wondering why strcmp() doesn't return true when comparing a string constant with a string that was acquired via a linked list. By the way, the data in the linked list was taken from a text file. Does that imply that there's a new line (\n) character in the string from the linked list?

    Code:
    struct Node{
    	char ACNO[15];
    	struct Node *next;
    } *start, *end;
    
    static char acctNum[20];
    
    ... locateUser(acctNum); ...
    
    void locateUser(const char* a){
    	// Locate user in the master file
    	struct Node *temp;
    	temp = start;
    
    	while(temp){
    		if(strcmp(a, temp->ACNO)){
    			printf("match");
    		}
    		temp = temp->next;
    	}
    }

  2. #2
    Join Date
    Jul 2013
    Posts
    30

    Re: strcmp on Linked List data and string constants?

    sorry, it seems to be working just fine. strcmp() returns a 0 when both character arrays are the same.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured