Thread: hi all(function problem )

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    16

    Exclamation hi all(function problem )

    hi all i am new here
    straight to the point
    --------------------------------------------------------
    Code:
    #include<stdio.h>
    
    
    
    void ekleme( int *s, int *t )
    {
    	while('\0' != *s)
      {
        ++s;
      }
      
        while('\0' != (*s = *t)){
        ++s;
        ++t;
      }
    
    }
      
    
    
    
    
    
    
    
    main(){
           
        int a;   
        int b=0,c=0;
          
        char string1[1000],string2[1000];   
           
           while((a=getchar()) !=EOF)
                string1[b++]=a;
              
                string1[b]=0;         
           
           
            while((a=getchar()) !=EOF)
                string2[c++]=a;
              
              string2[c]=0;
           
           
      void ekleme( int *string1, int *string2 );
           
           printf("%s",string1);
        
           
           getchar();
           return 0;
           }
    ---------------------------------------------------

    this is my source code
    it is a program to copy the string2 to the end of string 1 by calling ekleme routine with pointers

    In the book i study c programming i can solve every problem so far without calling functions in main including this one but not with functions like ekleme

    i think i am doing something wrong here with the function but what?

    i would be grateful if someone can explain
    thanks

    p.s. compiler gives me error messages if i dont use
    void ekleme( int *string1, int *string2 );
    in everywhere why is that?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    void ekleme( int *string1, int *string2 );
    is function prototype not function call

    function call will be

    ekleme( string1, string2 );
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    [Warning] passing arg 1 of `ekleme' from incompatible pointer type
    i get this warning when i do it and it still doesn t work properly

    it is the same
    just prints the string1 as it is in the beginning...

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    prototype of ekleme (why not myStrCat?) should be

    void ekleme(char* dst, const char * src);

    You have problems with entering 2 strings... After stdio receives EOF it cannot give you any char without resetting the error flag

    Maybe - better to stop on \n? or even use fgets instead of loop?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    You have problems with entering 2 strings... After stdio receives EOF it cannot give you any char without resetting the error flag

    but i tested that
    both of the strings are there when i say printf string 2 or 1

    void ekleme(char* dst, const char * src); why constant char?

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    hi again

    i get the code to work but only when i do the following:
    1-compile and run
    2-write something on keyboard for string1
    3-press Enter twice but why?
    4-put EOF character
    5-press enter once
    6-write something on keyboard for string2
    7-press Enter twice
    8-put EOF character
    9-press enter

    voila!!
    string2 is copied to the end of string1

    only on one of the step 3 and 7 you have to press Enter twice

    does this have something to do with getchar()?
    and how do i get input from keyboard to assign arrays by any other way


    thanks
    Last edited by benhaldor; 08-11-2007 at 04:14 PM.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    i have another function problem
    any help would be good

    Code:
      
    
    
    #include<stdio.h>
    #include<ctype.h>
    
    int i,d;
    void rever(char string1[],char string2[])
    {
        extern int d,i;
    
        string2[i++]=string1[d--];    
         
           if(d>=0)
    /*12.line*/    rever( string1[],string2[]);
        
        }
    
    
    
    
    
    main(){
          extern int d,i;
          int a,b,c;
          extern char string1[1000],string2[1000];
          
          
          a=0;
          while((b=getchar()) !=EOF)
                string1[a++]=b;
              
                 string2[a]=0; 
           
           d=a-1;
          i=0; 
     /*34. line*/    rever(string1[],string2[]);
           string2[i]=0;
          
          
           printf("%s",string2);
           
        
           
           getchar();
           return 0;
           }

    i get this error as usual

    syntax error before ']' token
    line 12 and 34(both lines when i call rever() function)
    i always get this but why?

    again any help at all will be appriciated

  8. #8
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by benhaldor View Post
    syntax error before ']' token
    line 12 and 34(both lines when i call rever() function)
    i always get this but why?
    Its a syntax error. just as the compiler tells.
    Try
    Code:
    rever( string1,string2);
    Kurt

  9. #9
    Registered User
    Join Date
    Aug 2007
    Posts
    16
    yeah thanks zuk

    actually i figured it out by myself before you posted but thanks anyway

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM