Thread: calling a char *function

  1. #1
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

    calling a char *function

    I have a function, char *move(Head head);

    It has already been declared and the function is created.

    However, when I try calling it from main like:

    move(head);

    It says implicit declaration.

    If I try:

    *move(head); - it gives me an error, likewise for &move(head) - how do I call this type of function?
    =========================================
    Everytime you segfault, you murder some part of the world

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Have you prototyped it?

    As in, at that point in the program is it declared?

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Yes, it's declared in a header file, it's not the only function declared in a header file, so I don't get why it's causing problems.
    =========================================
    Everytime you segfault, you murder some part of the world

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Code posty time

  5. #5
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Hmm I can't post the code unfortunately, it's an assignment =( . I don't want someone copying the code (just incase someone from my class is in here) and then they copy something from me and then when they do a plagiarism test, I may get busted.

    But it looks something like this:



    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct buffer *EX;
    struct buffer {
      char *buffer;
      EX next;
    };
    
    EX makeNode (void);
    char *move (EX ex);
    
    int main (void) {
      char str[] = "hi, \nmy name is Jude\n";
      int t_len;
    
      t_len = strlen(str);
    
       //do stuff with strings
    
      move(ex);
    
      return  0;
    }
    
    //other functions
    
    char *move (Ex ex) {
      char *buf;
      //stuff
    
      return (buf);
    
      } 
    
    
    EX makeNode(void){
    
      EX node;
      node = (EX)malloc(sizeof(*node));
    
      return (node);
    }
    =========================================
    Everytime you segfault, you murder some part of the world

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Spot the difference:

    Code:
    char *move (EX ex);
    char *move (Ex ex)

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    Code:
    char *move (Ex ex) {
      char *buf;
      //stuff
    
      return (buf);
    
      }
    That should be

    Code:
    char * move(EX ex)
    also, you don't declare the 'ex' you are passing to move in main()
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  8. #8
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by rags_to_riches View Post
    Spot the difference:

    Code:
    char *move (EX ex);
    char *move (Ex ex)
    Sorry, that wasn't there in the original code, that was just a typo as I was typing it out here.
    =========================================
    Everytime you segfault, you murder some part of the world

  9. #9
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Nvm, I found out what was wrong.

    The original was actually dumpTB

    and I had called it dump, missing the TB, that's why it was implicit. Damn silly mistakes.

    Sorry all
    =========================================
    Everytime you segfault, you murder some part of the world

  10. #10
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Seriously, I'd avoid 'masking' pointers... unless your assignment says you have to. Kinda hard to follow IMO.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  2. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM