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!
Re: Starting with C, need some help
Thanks for sharing a great coding.
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.
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);
}
void LimitesImprime(int linf, int lsup)
{
printf("Limites: [%d, %d]",linf,lsup);
}
int main()
{
int linf = 0;
int lsup = 0;
LimitesLee(&linf,&lsup);
LimitesImprime(linf,lsup);
system("pause");
return 0;
}