2017-07-09 6 views
-4

私はポインタに関するいくつかの基本的な質問があります。私はchar配列を持っています。関数を使ってchar配列をいくつか抽出しています。値を返してコードを出力したいのですが、 、あなたの助けスタックオーバーフローにfuctionの戻り文字

#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; 
} 
+1

ようこそに感謝します! [ツアー](https://stackoverflow.com/tour)、 を見て、[ヘルプセンター](https://stackoverflow.com/help)、特に を読んでください[どのようにして私は良い質問をしますか?](https://stackoverflow.com/help/how-to-ask) と[ここではどのような話題がありますか?](https://stackoverflow.com/help/on-トピック)。 –

答えて

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 ; 
} 
// 
関連する問題