Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
Ever want to impress your boss or that special someone?

Learn the basics of wine tasting from glassware to history to tasting techniques in this online course. This is a course you're sure to enjoy!
From our sponsors
C語言 函數問題
Dec 31st 2013, 15:32

題目:輸入一字串,並輸入開始位置及長度,取此字串的內容
例 字串=abc1234567 start=2 length=8
      結果=c1234567

我的程式如下: 

char a[50] ,b[50];
int i , j , start , len ;

void func()
{
      
      for(i=0;i!=len;i++,start++)     
      b[i]=a[start] ;
    
      return ;
      }
      
      int main()
      {
          
          printf("輸入字串:");
          scanf("%s" ,&a);
          printf("start=");         /*開始位置*/ 
          scanf("%d" , &start);
          printf("length=");         /*長度*/ 
          scanf("%d" , &len);
          
          func();
          
          printf("\n\n結果=%s" , b);

          system("pause");
          return 0;
          }

但問題是
因為我是設a[50] 
而如果我length輸入超過50 程式就會出錯
我該如何不改a[50]的50也能讓程式不出錯 
並讓結果輸出空白呢(因為沒有輸入所以為空白)

例如 字串=12345 start=2 length=50000000000
         結果=2345

另外
如果我將 

char a[50] ,b[50];
 int i , j , start , len ;
放如main() 裡面
那接下來的func()   裡面要怎麼改也能正常執行??

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 rrhhs 的頭像
    rrhhs

    線上遊戲排行榜2013/2014,進擊的巨人線上看,candy crush saga外掛,正妹寫真三圍

    rrhhs 發表在 痞客邦 留言(0) 人氣()