I need help for this code
i tried but it could give me what i want
what does the following function do?
Code:
int main(void) //what is this line doing here??
int fx(char *s) { //this is the first line of a function which returns an int
int i; //this creates an integer (hence 'int') but you must initialize it to 0 by adding "= 0" //before the semicolon
while (*s!= '\0') { //this is the first line of a while loop (and says loop while whatever is //being pointed at by the char pointer 's' does not equal a null-terminating character
s++; //this increments the 's' pointer to the next char location in memory
i++; //this increments i
}
rturn //this is supposed to be "return i;" without the quotes
}
what is wrong with this code of mine?
Code:
int a[10], i, *p; //what is this????
//Maybe you were trying to do something like this:
//int a[10]; //int array of 10 elements (0 -9)
//int i = 0; //integer initialized to 0
//int *p = &i; //get a pointer to 'i'
*p=10; //dereference the pointer and assign 'i' to 10
for(i=10; i>0; i--) a[i] = i*i; //this is WRONG...
//change to:
//for (i = 9; i > 0; i--) a[i] = i*i; //now you're not trying to access an element of the array
//which doesn't exist
p = a; //assign the pointer the address of the array
printf(%dn\,*(p+4)); //i don't think this is correct...