Thread: How to get result from display function ?

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    81

    How to get result from display function ?

    Hi

    How to get result from display function ?

    Code:
    #include <stdio.h> 
    struct student
    {
        int x;
        int y;
    };
     
    struct student* display(struct student *point);
     
    int main()
    {
        struct student mypoint;
    	
        mypoint.x = 72;
        mypoint.y = 22;
    	
        display(&mypoint);   
         
        return 0;
    }
    struct student* display(struct student *point) 
    {
      printf("\n Displaying information\n");
      printf("\n x: %d", point->x);
      printf("\n y: %d", point->y);
       
      return point;
    }
    Displaying information


    x: 72
    y: 22

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you're talking about how to save the displayed output to a string: do it in the opposite order, i.e., write a function that generates the required string, then print the string or do whatever else you want with it. Using sprintf or more safely snprintf may come in handy instead of printf.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    81
    Quote Originally Posted by laserlight View Post
    If you're talking about how to save the displayed output to a string: do it in the opposite order, i.e., write a function that generates the required string, then print the string or do whatever else you want with it. Using sprintf or more safely snprintf may come in handy instead of printf.
    Function return integer value
    Code:
    int display (void){
        int returndata;
        
        return returndata
    }
    Function return char
    Code:
    char display (void){
        char returndata;
        
        return returndata;
    }
    What the value this would be return
    Code:
    struct student*display (void){
         struct student *point;
        
        
    return point;
    }
    What happen when we call to this function. I have read it when function execute it would return only one value. What type of value it would return integer, character, float, string ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Err... the return type is right there for you to see: struct student *
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-23-2016, 11:48 AM
  2. void display record and other funcntion to call result
    By 16800960 in forum C++ Programming
    Replies: 0
    Last Post: 06-03-2010, 09:15 PM
  3. unexpected result, no display of input string
    By xephyr in forum C Programming
    Replies: 11
    Last Post: 08-04-2004, 07:22 PM
  4. Replies: 10
    Last Post: 03-19-2003, 02:15 PM
  5. display int result (newbie)
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 07-03-2002, 01:11 AM

Tags for this Thread