Hello!
There are quite a few oddities in your program. The main oddity that prevents
it to work has been reported above by vishweshgm, the printf call is wrong.
But beside this:
- You don't need a global variable for index.
- You are writing a print_routine which does nothing more than printf itself.
-> What's the point?
- As your data consists in strings, there is no point making them unsigned,
it will just bring extra compilation warnings.
I tried this:
Code:
#include <stdio.h>
char A1[] = "12345";
char A2[] = "ABCDE";
char B1[] = "67890";
char B2[] = "FGHIJ";
char C1[] = "13579";
char C2[] = "KLMNO";
char *Data[6] ={A1,A2,B1,B2,C1,C2};
void print_routine(char *ptr) {
printf("%s\r\n",ptr);
}
void main() {
char i;
for(i = 0 ; i < 6 ; ++i) {
print_routine(Data[i]);
}
}
Compiles without any error or warning using MacOS. The result is like this:
Code:
Mac-mini:TestC dora$ cc -o TestC TestC.c
Mac-mini:TestC dora$
Mac-mini:TestC dora$ ./TestC
12345
ABCDE
67890
FGHIJ
13579
KLMNO
Mac-mini:TestC dora$
NB: I removed the infinite loop because I don't remember how to get a delay on
MacOS, but basically everything works as long as the printf line is corrected.
@KLAUS:
BTW: you usually don´t pass an array to a function.
Sorry, I'm not really a programming specialist, so I may be wrong on this one, but
if he passes Data to his function, it looks like he's passing a pointer to a
string. Data is an array of 6 pointers to strings. Therefore, any of its elements
is a pointer to string. Is this wrong?
And beside this, I don't understand this:
You can increment 1234, but you cant increment a string. You can´t increment "1234"
Where is he incrementing a sting? As I understand his code, he's just incrementing
a global index.
Dora.