Basicaly I want to see if a a number (in my example: 12345678910 ) contains another, smaller number (1234). For this I decided to turn a into a string. For some reason my "in" function never worked. But now for some reason if I ever decide to invoke, there's a segmentation fault BEFORE the program reaches it. Try it out: Compile and run it, then do it again with the line //in(buffer,b); uncommented.
Don't be afraid of the huge lines of code. The problem (I hope) should be quite simple to solve :p
Also, ignore most of the commented "crap", it's just a rough scratch at this point.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*void num_gen (number)
{
int hits;
char string[3];
itoa(number,string,10);
for (i;i<10000;i++)
{
if(in(number,i)==1)
hits++;
}
return;
}*/
void in (char *a,char *b)
{
//printf("a: %s \n",a);
//printf("b: %s \n",b);
//printf("strlena: %d \n",strlen(a));
//printf("strlenb: %d \n",strlen(b));
char current[strlen(a)+1];
int i;
for (i=0;i<=strlen(a)-strlen(b);i++)
{
//printf("%c",b[0]);
int x;
for (x=0;x<strlen(a);x++)
{
//printf("b[i]=%d\n",b[i]);
current[x]=b[i+x];
//if (x==strlen(a))
//current[x+1]="\0";
}
//printf ("%s \n",current);
}
return;
}
int main(void)
{
int number=1234;
char buffer[10];
sprintf(buffer, "%i", number);
printf("Convertion to string is done\n");
printf("TESTE");
printf("Number: %s \n",buffer);
char b[20]="12345678910";
printf("TEST");
printf("Num 0: %c",buffer[0]);
printf("END TESTE");
//in(buffer,b); //the shit hits the fan?
return 0;
}