Thread: Passing char as an array?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    23

    Passing char as an array?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #define SIZE 81
    
    
    void display(char *pointerCheck[]);
    
    int main(void)
    {
       char str1[] = "0806509597";
       display(&str1[]);
      
    }    
    
    void display(char *pointerCheck[])
    {
        
       int w = 0;
       int x = 0;
       int temporary[10];
       int y = 0;
       int finalOutput;
       char pointer[10];
       int finalCheck; 
    
    	for (x = 1; x <= 10;x++)
    	{
    	   if (x == 10)
    		{
    		   printf("Trial goto\n");
    	  	   goto baba;
    		}
    
        	   pointer[w] = *pointerCheck[w];	
    	   temporary[x] = atoi(&pointer[w]);
    
    
    	   y = temporary[x] * (w + 1);
    	   finalOutput += y;
       	   printf("%d\n",y);
               w++;
    	   
    	   baba:	
    	   if(x == 10)
    		{
    		  finalOutput = finalOutput % 11;
    		  finalCheck = atoi(&*pointerCheck[9]);
    	  	 if (finalOutput == finalCheck)
    	       	   {
    			printf("Pokemon");
    	           }
    		}; 
    	}
    }
    ~Posted in another forum, but didn't get much of an idea~

    Good day, I am having a problem with properly passing my str1 with the string included. Anyone can help me fix this? thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Currently your display function doesn't take a string, but rather an array of strings, which you then seem to believe is an array of chars. You should probably pick one and go with it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Seems like half the posts are cross-posts all of a sudden
    Passing a char array. - Dev Shed
    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. Passing char array to fuction
    By taurus in forum C Programming
    Replies: 12
    Last Post: 10-09-2009, 06:07 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM