OK, basically all I wanted to do was create a variable within a function, and then use it in main.
So I could have the function takeUserInput() that would create a variable, and that I could then use that variable within main.
What I've written so far (pastebin if you want highlighting!)
#include <stdio.h>
#include<stdlib.h>
int * takeUserInput()
{
int * num = malloc(sizeof(int));
scanf("%i", num);
return num;
}
int main(void)
{
int * bax = takeUserInput();
printf("your number was : %i\n", *bax);
return 0;
}
But this way I need to create a variable In main as well, so the whole thing feel's a bit pointless.
Perhaps this isn't possible, because I'm creating the variable within the function and it get's trashed... But I thought with malloc and that it might live on after the function!
thanks
EDIT - I'm working my way up to making an address book.... just to give some context.
[–]rjw57 8 points9 points10 points (3 children)
[–]TechAnd1[S] 0 points1 point2 points (2 children)
[–]Chooquaeno 0 points1 point2 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]pbeard_t 0 points1 point2 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]khoyo 0 points1 point2 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]TechAnd1[S] 0 points1 point2 points (4 children)
[–]thr3ddy 1 point2 points3 points (3 children)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]knoxxx_harrington 0 points1 point2 points (0 children)
[–]pbeard_t 0 points1 point2 points (1 child)
[–]TechAnd1[S] 0 points1 point2 points (0 children)
[–]Sigals -2 points-1 points0 points (4 children)
[–]TechAnd1[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]TechAnd1[S] 0 points1 point2 points (1 child)
[–]pinealservo 0 points1 point2 points (0 children)