Character passing through functions

This is a discussion on Character passing through functions within the C Programming forums, part of the General Programming Boards category; i am having trouble with program, can someone tell me what' s wrong? insert Code: #include <stdio.h> void asd (const ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    Unhappy Character passing through functions

    i am having trouble with program, can someone tell me what' s wrong?

    insert
    Code:
    #include <stdio.h>
    
    void asd (const char phase);
    
    int main (void){
        char phase[5]; 
        while(1==1){
             printf("Enter Phase > ");
             gets(phase);
             if(strcmp(phase,"TTYL")==0){
               printf("talk to you later\n");
               system("PAUSE");
               return (0);
             void asd (const char phase);
        }
    }
    
    void asd (const char phase){
         if(strcmp(phase,"CU")==0){
               printf("see you\n");
             }else if(strcmp(phase,":-)")==0){
               printf("I am happy\n");
             }else if(strcmp(phase,":-(")==0){
               printf("I am unhappy\n");
             }else if(strcmp(phase,";-)")==0){
               printf("wink\n");
             }else if(strcmp(phase,"??)==0){
               printf("sleepy\n");
             }else if(strcmp(phase,"TA")==0){
               printf("totally awesome\n");
             }else if(strcmp(phase,"CCC")==0){
               printf("Canadian Computing Competition\n");
             }else if(strcmp(phase,"CUZ")==0){
               printf("because\n");
             }else if(strcmp(phase,"TY")==0){
               printf("thank-you\n");
             }else if(strcmp(phase,"YW")==0){
               printf("you are welcome\n");
             }else {
               printf("What The Hell???\n");
                   }
    }


    the passing of char phase doesn't work.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    phase is the name of a char array.

    When you pass an array name to a function, you're passing a pointer to the array's base address.

    Make the parameter "char *phase, in the receiving function. (or char phase[]).

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    What Adak said, and I'm surprised that code would even compile after looking at this line (unless you typed it in the thread window).

    Code:
             }else if(strcmp(phase,"??)==0){
               printf("sleepy\n");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing by reference to functions
    By avi2886 in forum C Programming
    Replies: 12
    Last Post: 03-03-2009, 01:56 PM
  2. Trouble passing args to functions in other files
    By Midnight Coder in forum C Programming
    Replies: 6
    Last Post: 01-03-2009, 05:13 PM
  3. Help Understanding Passing Arrays To Functions
    By jrahhali in forum C++ Programming
    Replies: 7
    Last Post: 04-10-2004, 03:57 PM
  4. passing array structures to functions
    By lukejack in forum C Programming
    Replies: 2
    Last Post: 04-08-2003, 03:17 PM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21