C
Carramba
hi!
the code is cinpiling with gcc -ansi -pedantic. so Iam back to my question
Iam trying to make program were I enter string and serach char.
and funktion prints out witch position char is found this
is done if funktion serach_char. so far all good
what I want do next is:
return, from funktion, pointer value to array were
positions ( of found char) is stored. and print that array from main.
but I only manage to print memory adress to array..
any suggestions?
#include <stdio.h>
int search_char( char *pStr , char *pSearch );
int main(void){
char cStr[201];
char cSearch[21];
int *pInt;
int i ;
printf("Enter string\n");
scanf("%s", cStr);
printf("Enter search char\n");
scanf("%s", cSearch); /*reading it as string becouse I want to
by able later search 2 chars and more*/
*pInt = search_char( &cStr , &cSearch );
for(i=0;i<20;i++){
printf("%d\n",&pInt[0]);
}
return 0;
}
int search_char( char *pStr , char *pSearch ) {
int i;
int vPossition[201];
for( i=0;i<=200;i++){
if(pStr == pSearch[0]){
printf("Found %c in position %d \n", pStr,i+1);
vPossition = i;/*position into array*/
}
}
return vPossition;
}
--
Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.
the code is cinpiling with gcc -ansi -pedantic. so Iam back to my question
Iam trying to make program were I enter string and serach char.
and funktion prints out witch position char is found this
is done if funktion serach_char. so far all good
what I want do next is:
return, from funktion, pointer value to array were
positions ( of found char) is stored. and print that array from main.
but I only manage to print memory adress to array..
any suggestions?
#include <stdio.h>
int search_char( char *pStr , char *pSearch );
int main(void){
char cStr[201];
char cSearch[21];
int *pInt;
int i ;
printf("Enter string\n");
scanf("%s", cStr);
printf("Enter search char\n");
scanf("%s", cSearch); /*reading it as string becouse I want to
by able later search 2 chars and more*/
*pInt = search_char( &cStr , &cSearch );
for(i=0;i<20;i++){
printf("%d\n",&pInt[0]);
}
return 0;
}
int search_char( char *pStr , char *pSearch ) {
int i;
int vPossition[201];
for( i=0;i<=200;i++){
if(pStr == pSearch[0]){
printf("Found %c in position %d \n", pStr,i+1);
vPossition = i;/*position into array*/
}
}
return vPossition;
}
--
Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.