史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   關於C++的 string的作業... (http://forum.slime.com.tw/thread159907.html)

ice6 2005-11-01 10:15 PM

關於C++的 string的作業...
 
這次老師出的作業實在令我頭痛...懇請高手幫個忙....

------------要求的輸出結果如下--------------------
Enter a line: This is a sample

Num Position Length Word
1--------0---------4----------This
2--------5---------2--------------is
3--------8---------1--------------a
4------10---------6-------sample

-----------分格線----------------------------------------
一堆"-"是要整理位置 跟輸出無關 OTZ
Num = 第?個字
Position = 字的起始位置
Length = 字的長度
Word = 字長的樣子 = =||

老師的主題在string上面...但我會的東西感覺太少
或者說我活用能力太差也說不定...
總之 先謝謝各位的幫忙了 :ddrf567h:

getter 2005-11-02 12:11 AM

#include <stdio.h> /* 載入引導檔 stdio.h */
main()
{
int len,i,jc,cp,space,co[10][2]={0};
char text_in[50]="",ct[10][50]={0};
system("cls");
printf("請輸入英文字? ");
gets(text_in);

len=strlen(text_in);

space=0;
jc=0;
cp=0;
for(i=0;i<len;i++)
{
jc++;
if(i==0 & text_in[i]!=' ')
{
co[space][0]=i;
space++;
}

if(text_in[i]==' ')
{
co[space][0]=i+1;
co[space-1][1]=jc-1;
jc=0;
cp=0;
ct[space-1][cp-1]='\0';
space++;
}
else
{
ct[space-1][cp]=text_in[i];
cp++;
}
}
co[space-1][1]=len-co[space-1][0];

printf("%s\n",text_in);

printf("\nNum\tPosition\tLength\t\tWord");
for(i=0;i<space;i++)
{ printf("\n%3d\t%8d\t%6d\t\t%s",i+1,co[i][0],co[i][1],ct[i]); }

printf("\n\n");
system("pause");
}


http://img26.paintedover.com/uploads/26/test_11.jpg

是這樣嗎 ??

ice6 2005-11-02 11:03 PM

ㄜ...請問上面的 引導檔案 在哪裡阿? VB內建會有嘛?
而且老師要求我們用string來做 不給我們用array來取輸入值ˊˋ
不過還是謝謝大大的寶貴資料 OTZ

getter 2005-11-02 11:13 PM

這是 DEV-C++ ver4992 的 X.X 寫的可以相容在舊的 Turbo C 上
基本的概念應該會差不多...

mini 2005-11-03 09:13 AM

這裡給你參考
http://66.102.7.104/search?q=cache:a...&lr=lang_zh-TW

重點就是
#include <string.h> // 引入字串函數標題檔

ice6 2005-11-06 04:19 PM

嗯嗯...感謝兩位解答 OTZ


所有時間均為台北時間。現在的時間是 12:36 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1