I know an element in an array, say file1[10][10].
I know a pointer to one of the character in file1[10][10]
*****************
say if I have file1[10][10]="whereiam"
and I know a pointer to "i" in whereiam
I want to print "where"
I tried this, but have problem with these pointers.
*******************
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char *s[30];
char ch, ch1[100][100];
char file1[100][100], file2[100][100];
int i=0, j, k, l, z=0, m, collect[100];
char one_file[] = "one.txt";
char two_list[] = "two.txt";
char file_list[100][100];
FILE *one,*two;
clrscr();
one = fopen(one_file,"r");
two = fopen(two_list, "w");
while((ch=getc(one))!=EOF)
{
if(ch=='"') /*trying to search text between "..."*/
{
j=0;
while((ch=getc(one))!='"')
{
file1[i][j]=ch; /* text between "...." is stored*/
fprintf(two, "%c", ch);
j++;
}
file1[i][j]='\0';
fputc('\n',two);
i++;
}
}
for(k=0;k<i;k++) /*trying to search stringf in file1 with "text"*/
{
s[k]=strstr(file1[k],"text");
if(s[k]!=NULL)
{
printf("\n\n%s",s[k]);
collect[z]=k;
z++;
}
}
/*if i have text "org.text#extra" , i get a pointer to "t" in org.text from above s[k]*/
/* i actually want org.text. I know pointer to "o" in org.text#extra, and i know pointer to "t". */
/*Now I am trying to read from pointer to "o" to pointer to "t"*/
/* to try this i implemented as below, this goes to infinite loop*/
for(k=0;k<z;k++)
{
m=0;
while((file1[collect[k]])!=(s[k]-1))
{
file2[k][m]=file1[k][m];
m++;
++*file1[collect[k]];
}
file2[k][m+1]=NULL;
}
for(k=0;k<z;k++)
{
printf("\n\nfinal strings = %s",file2[collect[k]]);
}
fclose(one);
fclose(two);
return(0);
}