I've been playing around with this program for a bit and the implementation seems to be correct. However, I think I did something wrong when trying to print out the characters of the 2d array. What did I do wrong??
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
int main(){
char listWords[10][10]; //10 strings of a maximum of 5 characters each
char msg[50] = "this is a test"; //now split the msg and put the words in listWords
int column = 0;
int wordSize = 0;
int index = 0;
while (msg[index] != '\0') {
if (msg[index] != ' ') {
listWords[column][wordSize] = msg[index]; //add character
wordSize++;
}else{ //if space is found
listWords[column][wordSize] = '\0';
column++;
wordSize = 0;
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
printf("%c ", listWords[i][j]);
}
printf("\n");
}
return 0;
}