M
mdh
In trying to understand the issue, I wrote this;
#include <stdio.h>
void f_output(char arg1[6], int limit);
int main () {
f();
return 0;
}
void f(void) {
char matrix[2][6] ={ {'h','e','l','l','o','\0'},
{'w','o','r','l','d','\0'}};
f_output(matrix, 10);
}
void f_output(char *s, int limit) {
int x, i;
for (i=0; i < limit; i++)
printf("%s\n", s++);
}
Desired output: "Hello world"
Actual output:
hello
ello
llo
lo
o
world
orld
rld
ld
My naive way of looking at this was to assume that the declaration
"void f_output(char arg1[6], int limit)"
would "tell" the pointer that the type was an array of 6 chars, hence s
++ would increment to matrix[2]. I understand this is a totally
useless and pointless function, except in trying to further my
understanding...so please go easy!!!
#include <stdio.h>
void f_output(char arg1[6], int limit);
int main () {
f();
return 0;
}
void f(void) {
char matrix[2][6] ={ {'h','e','l','l','o','\0'},
{'w','o','r','l','d','\0'}};
f_output(matrix, 10);
}
void f_output(char *s, int limit) {
int x, i;
for (i=0; i < limit; i++)
printf("%s\n", s++);
}
Desired output: "Hello world"
Actual output:
hello
ello
llo
lo
o
world
orld
rld
ld
My naive way of looking at this was to assume that the declaration
"void f_output(char arg1[6], int limit)"
would "tell" the pointer that the type was an array of 6 chars, hence s
++ would increment to matrix[2]. I understand this is a totally
useless and pointless function, except in trying to further my
understanding...so please go easy!!!