Results 1 to 3 of 3

Thread: Starting with C, need some help

  1. #1

    Default Starting with C, need some help

    Well guys Im starting with C and Im doing a really simple program, but its giving me some issues Maybe you will be able to help me, thats my code
    #include <stdlib.h>
    #include <stdio.h>
    void LimitesLee(int linf, int lsup)
    {

    printf("Introduzca limite inferior y superior.\n");
    scanf("%d",&linf);
    scanf("%d",&lsup);
    /*if(linf>lsup){
    LimitesLee(linf,lsup);
    */
    }

    void LimitesImprime(int linf, int lsup){
    printf("Limites: [%d, %d]",linf,lsup);
    }
    /*int EnteroAleatorio(){
    int a;
    rand();
    a = rand()
    if(a>

    return rand();
    }

    */int main()
    {
    int linf = 0;
    int lsup = 0;
    LimitesLee(linf,lsup);
    LimitesImprime(linf,lsup);

    system("pause");
    return 0;
    }

    The prob is that when I set the "linf" and the "lsup" the function LimitesImprime still giving me the 0,0 values instead the values that I set
    Thanks for your time I hope you can answer me!

  2. #2
    Join Date
    May 2013
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt/Embedded
    Platforms
    Windows

    Default Re: Starting with C, need some help

    Thanks for sharing a great coding.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Starting with C, need some help

    Read about the how to pass parameters to a function, like pass the value, pass the address (by pointer). Here you need use the second one.

    Qt Code:
    1. #include <stdlib.h>
    2. #include <stdio.h>
    3.  
    4. void LimitesLee(int * linf, int * lsup)
    5. {
    6. printf("Introduzca limite inferior y superior.\n");
    7. scanf("%d",linf);
    8. scanf("%d",lsup);
    9. }
    10.  
    11. void LimitesImprime(int linf, int lsup)
    12. {
    13. printf("Limites: [%d, %d]",linf,lsup);
    14. }
    15.  
    16. int main()
    17. {
    18. int linf = 0;
    19. int lsup = 0;
    20.  
    21. LimitesLee(&linf,&lsup);
    22. LimitesImprime(linf,lsup);
    23.  
    24. system("pause");
    25. return 0;
    26. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Starting all over
    By KillGabio in forum Newbie
    Replies: 4
    Last Post: 17th January 2013, 14:34
  2. 0xc0000005 when starting exe
    By dAnieL_dE in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2012, 23:18
  3. Starting with QML
    By MTK358 in forum Newbie
    Replies: 5
    Last Post: 3rd October 2010, 13:36
  4. Questions before starting with Qt
    By MartinM in forum Newbie
    Replies: 6
    Last Post: 24th April 2010, 09:49
  5. Error starting Qt
    By shamik in forum Installation and Deployment
    Replies: 1
    Last Post: 18th April 2007, 12:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.