View Code of Problem 3832

#include<stdio.h>
#include<string.h>
int main()
{
	char str[1000];
	while (scanf("%s",&str)!=EOF)
	{
		char str1[100];
		int *ch;
		scanf("%s",&str1);
		ch = strstr(str,str1);
		if (ch != NULL)
			printf("%d\n", ch - str + 1);
		else
			printf("-1\n");
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:6:17: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  while (scanf("%s",&str)!=EOF)
                ~^  ~~~~
Main.c:10:11: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
   scanf("%s",&str1);
          ~^  ~~~~~
Main.c:11:6: warning: assignment to 'int *' from incompatible pointer type 'char *' [-Wincompatible-pointer-types]
   ch = strstr(str,str1);
      ^
Main.c:13:22: error: invalid operands to binary - (have 'int *' and 'char *')
    printf("%d\n", ch - str + 1);
                      ^
*/

Double click to view unformatted code.


Back to problem 3832