KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've created a function that takes a pointer to the first element in a C-String array. This is the array, and how I went about making it: char element1[60] = "ubunz"; char element2[60] = "uasdasffdnz"; char* array[10] = {element1,element2}; Then I created a pointer to the first element in the array: char *pointertoarray = &array[0]; Then I passed the pointer to the function I made: void printoutarray(char *pointertoarray){ int i = 0; while (i < 2){ printf("\n Element is: %s \n", *pointertoarray); pointertoarray = pointertoarray + 1; i = i+1; } } When I run the program the array never prints out. I've done this program before in C++ but I used the STL string type, and made a pointer to an array of strings. I think my problem lies with the way I'm going about making an array of strings in C, and making a pointer to it.
Tags (comma-separated)
Save Edits
Cancel