Issue
I'm trying to find to find which position a number has in a sentence in c. I'm kinda new to programming and i don't know why my code isn't working.
i keep getting this warning but i have no clue what it means (english isn't my first language):
passing argument 1 of 'strcmp' makes pointer from integer without a cast [-Wint-conversion] Main.c /TweeIntegers line 20 C/C++ Problem
My code:
#include <stdio.h>
#include <string.h>
int main()
{
int i, y;
char x;
char text1[] = "een stuk text";
char text2[] = "k";
for ( i = 0; i < strlen(text1); i++ )
{
x = text1[i];
y = strcmp( x, text2 )
}
printf("%d", i);
return 0;
}
Solution
if you are only looking for a char and the first position then you can use the following code:
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char text1[] = "een stuk text";
char charYouLookFor = 'k';
for ( i = 0; i < strlen(text1); i++ )
{
if (text1[i] == charYouLookFor)
break;
}
printf("%d", i);
return 0;
}
If you are looking for the position of a text in a text or for the second position of the char the code needs to be more complex.
Answered By - Ludger H. Answer Checked By - Cary Denson (PHPFixing Admin)