How would i implement this?Im trying to compare a array of c strings to a single string and if there is no match append it to the 2d array.
char*mprt,uni[100][16];
mprt = &uni[0][0];
for (int s = 0;s <= 99;s++)
{
for (int z = 0;z <= 15;z++)
{
if (strcmp(mprt++, string1) != 0)
{
uni[s][z] = string1[z];
}
}
}
Ok … from your comments I now get what you’re trying to do. You’d want to make this into a function so you could feed words to it, but it should get you pointed in the right direction.
Note that you can use
char[][], but this way your strings can be of any length because we dynamically allocate them when we put them in the list.For completeness, the
char[][]version:Edit to explain C pointers and arrays from comments below:
In C, arrays degrade to pointers. This is actually really confusing when you first start.
If I have
char myArray[10]and I want to pass that to a function that takes achar *argument, I can use either&myArray[0]or justmyArray. When you leave off the index, it degrades to a pointer to the first element in the array.In a multidimensional array like yours,
&uni[5][0]==uni[5]– both are pointers to the first element in the second dimension at index 5 in the first. It degrades tochar*pointed at the beginning of the 6th word in your list.