Thread: Third newbie question

  1. #16
    Registered User
    Join Date
    Nov 2009
    Posts
    111
    So, my problem isn't first with strlen(), but with the method i create and the passing of char arrays.

    I get the same warning just with this:
    Code:
            char str1[10] = "Myname";
            char str2[10] = "Myname";
            strcomp("MyName", "Myname");
    }
    
    int strcomp(char s1, char s2) {
    }
    So, what the error says is: When I pass the strings to the method, I pass pointers. The error is that I "make integers from pointers" without casting the integers?

    If I do this instead:
    Code:
    int strcomp(char *, char *);
    
    main{
            char str1[10] = "Myname";
            char str2[10] = "Myname";
            strcomp("MyName", "Myname");
    }
    
    int strcomp(char *s1, char *s2) {
    
    }
    then it compiles without warnings.

    However, trying to USE the pointers *s1 and *s1 afterwards...

  2. #17
    Registered User
    Join Date
    Nov 2009
    Posts
    60
    That's what I asked you to do. Now try to find out how to implement strcomp with pointers.

  3. #18
    Registered User
    Join Date
    Nov 2009
    Posts
    111
    Ok, this is what I "played" myself to:

    Code:
    int strcomp(char *, char *);
    
    main() {
            char str1[10];
            char str2[10];
            strcpy(str1, "Myname");
            strcpy(str2, "Myname");
     
            strcomp(str1, str2);
    }
    
    
    int strcomp(char *s1, char *s2) {
            printf("%s\n%s", s1, s2);
    }
    Let's see if I understand this...
    - Create two string variables
    - "Populate" the string variables
    - Run the strcomp method with the strings as parameters
    - The method takes to the value of the address pointed to by the string parameters, because a string variable is "allmost" a pointer in itself...

    Does this mean that all methods that are to receive strings must be defined to tak pointers as parameters? That's it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  2. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  3. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  4. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM