I am having a hard time making this work. Could someone give me some advice please?

This is a discussion on I am having a hard time making this work. Could someone give me some advice please? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <string.h> #include <stdlib.h> char (*s1)(char* (*ptr)(void)); char set_text(void); int main() { char *s2; s1(set_text); printf("%s\n", s2); ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Post I am having a hard time making this work. Could someone give me some advice please?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    char (*s1)(char* (*ptr)(void));
    char set_text(void);
    
    int main() 
    {
    char *s2;
    s1(set_text); 
    printf("%s\n", s2);
    return 0;
    }
    
    
    char set_text(void) {
    char text[] = "Hello World!";
    char *tmp;
    
    
    tmp = (char*)malloc((strlen(text) + 1) * sizeof(char));
    
    
    strcpy(tmp, text);
    return tmp;
    }
    
    

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why did you make 2 threads for the same thing? Pointer to function with string


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    Duplicate closed.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm having a hard time making a .exe from a .cpp
    By manugarciac in forum C++ Programming
    Replies: 10
    Last Post: 05-13-2009, 04:40 PM
  2. Hard time having SDL and OpenGL work together
    By indigo0086 in forum Game Programming
    Replies: 5
    Last Post: 07-05-2007, 10:21 AM
  3. priority list won't work, i give up
    By teamster in forum C Programming
    Replies: 8
    Last Post: 10-19-2006, 12:26 PM
  4. online games, making it hard to use hacks
    By muttski in forum Windows Programming
    Replies: 10
    Last Post: 05-13-2002, 10:32 AM
  5. Need to give user more time
    By Natase in forum C Programming
    Replies: 6
    Last Post: 09-16-2001, 05:21 PM

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