我有一些关于指针的基本问题,我有一个char数组,我正在使用函数提取一些单词我的char数组,我想返回值并打印它主要我有代码但它不起作用,谢谢你帮助
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char cumle[30];
char kelimecikart(char *cumle,char *sozcuk);
int main(){
int i;
char sozcuk[30];
printf("sentence:\n");
gets(cumle);
puts(cumle);
printf("What is the word you want to extract of:\n");
gets(sozcuk);
puts(sozcuk);
printf("\n");
cumle[0]=kelimecikart(cumle,sozcuk);
for(i=0;i<17;i++){
printf("%c",cumle[i]);
}
}
char kelimecikart(char *dizi,char *cikansoz)
{
int a = strlen(dizi);
int b = strlen(cikansoz);
int i,j,tmp=0;
for(i=0;i<a;i++){
for(j=0;j<b;j++){
if(*(dizi+i+j)==*(cikansoz+j)){
tmp++;
}
else{
break;
}
}
if(tmp==b){
i+=tmp-1;
}
else{
*(cumle+i)=*(dizi+i);
}
tmp=0;
}
return *cumle;
}
答案 0 :(得分:0)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char cumle[30];
void kelimecikart(char *cumle,char *sozcuk);
int main(){
int i;
char sozcuk[30];
printf("sentence:\n");
gets(cumle);
puts(cumle);
printf("What is the word you want to extract of:\n");
gets(sozcuk);
puts(sozcuk);
printf("\n");
kelimecikart(cumle,sozcuk);
for(i=0;i<17;i++){
printf("%c",cumle[i]);
}
}
void kelimecikart(char *dizi,char *cikansoz)
{
int a = strlen(dizi);
int b = strlen(cikansoz);
int i,j=1;
for(i=0;i<a;){
if(j==0){
i++;
}
else if(j==b){
break;
}
for(j=0;j<b;j++){
if(dizi[i]==cikansoz[j]){
i++;
}
else{
break;
}
}
}
for(;i<a;i++){
dizi[i-b]=dizi[i];
}
return ;
}
//