• ベストアンサー

ワード数の数え方教えて

大学の課題の締め切りが迫っています。皆さんの力を貸してください。 ファイルのデータ(英文)を読み込み、一行毎の文字数とword数を数えるプログラム。スペース込み。 例 I see your true colors (↓)(「←」はエンターキー) That’s why I love you(↓) Don’t be afraid to let them show ファイル名を入力して下さい: A:test2.txt(↓) 1: I see your true colors ==> 22文字、5ワード 2: that’s why I love you ==> 20文字、5ワード 3 : don’t be afraid to let them show ==> 31文字、7ワード       (↑実行結果)

noname#1519
noname#1519

質問者が選んだベストアンサー

  • ベストアンサー
  • selenity
  • ベストアンサー率41% (324/772)
回答No.1

学校の課題なので極力自分で考えましょう。 見る人が見れば、他人のを写したかどうかはすぐ分かります。 ヒントだけ、、、 ・ファイルを開くにはfopenを使います。  読み取りモードで開けばよいでしょう。 ・ファイルからの読み取りはfgetcで1文字ずつ  読み取ります。 ・0x0aの文字が来たら改行。 ・0x20の文字が来たら単語のカウントを増やす ・ファイルの末尾が空白出なければ単語のカウントを増やす といった感じで如何でしょう?

その他の回答 (1)

noname#151056
noname#151056
回答No.2

私だったらこんな感じ。 getsでファイル名を読んでfopen。 fgets で一行ずつ読む。 読み込んだ一行文字列データについて、一文字ずつ チェック&カウント。 ワードの区切り文字は isspace 関数で調べる。 fcloseして終了。 20~30行のプログラムでできると思います。

関連するQ&A

  • 日本語にしてください( ^_^)

    same if I don't see you clearly, you feel to be really beautiful and I love your eyes. お願いします!

  • 四つの短い英文についての疑問です

    1. she pointed out all of her flaws yet all all i could see was beauty. she revealed her darkest of secrets & my love for her went unchanged. 最初の文章は一体どこで切れているんでしょうか? 2. all i ask is that you be willing to be my last. "you be" という部分が変な気がします。何か省略されているんでしょうか? 3. "You gotta be around people who aren't afraid to tell you you're fucking up." とくに"gotta be around"が難しくて訳しきれないです。 4. they'll leave you for someone who doesn't love them simply because they don't love love themselves 自分では訳せているつもりですが、はて一体何のことを言っているのかわからない始末。どうも訳し方がまずいせいなのか。こんな短文すらうまく理解できなくて無念というか… w

  • ガストのCMソング

    ファミレスのガストのCMソングは誰の曲でしょうか? 「Why don't you let me see your smile~♪」みたいな歌詞だったと思います。 男性ボーカルで、平井堅さんのような声ですが、もしかしたら洋楽かも、、、。 わかる方、よろしくお願いします!

  • Don't Let Go の歌詞の意味

    Isaac Hayes "Don't Let Go" の日本語歌詞(意味)を教えてください。 特にDon't let goの部分が、、どれなのか、もしくはもっと別の意味なのか分かりません。。。よろしくお願いします! -僕を行かせないで Don't let(me)go -君を行かせない(行かせたくない) Don't let(you)go -諦めないで Don't let(it)go -離れないで Don't let(??)go Hear that whistle its 10 o'clock (Don't let go) (Don't let go) Come on baby it's time to rock (Don't let go) (Don't let go) I'm so glad I've got you here (Don't let go) (Don't let go) Keeps me grinnin' from ear to ear (Don't let go) (Don't let go) Oo-ee, mmm this feelin' is killin' me Aaaw shucks Well, I wouldn't stop for a million bucks (I love you so) Just hold me tight and don't let go Thunder, lightnin', wind and rain (Don't let go) (Don't let go) Love is formin' inside my brain (Don't let go) (Don't let go) I'm so eager I'm nearly dyin' (Don't let go) (Don't let go) You've been keepin' your lips from mine (Don't let go) (Don't let go) Oo-ee, mmm this feelin' is killin' me Aaaw shucks Well, I wouldn't stop for a million bucks (I love you so) Just hold me tight and don't let go, yeah Whooooa, yeah Don't let go Come on and kiss me, kiss me sweet Hold me tight baby and don't let go (Don't let go) Come on and love me You've gotta love me (Don't let go) I want ya, I want ya, I really, really want ya (Don't let go) All night, feels so right (Don't let go) Hold me tight, don't let go [Instrumental Interlude] Hound dogs barkin' upside the hill (Don't let go) (Don't let go) Love is draggin' him through the mill (Don't let go) (Don't let go) If it wasn't for havin' you, girl (Don't let go) (Don't let go) I'd be a-howlin' and a-barkin' too (Don't let go) (Don't let go) Ooh-ee, mmm this feelin' is killin' me Aaaw shucks Well, I wouldn't stop for a million bucks (I love you so) Just hold me tight and don't let go, no No, no don't let go I need ya so, girl Hold me, momma (Hold me tight if it takes all night) (But don't let go) Don't, don't let me go (I wouldn't stop for a million bucks) ('Cause I love you so) No, no, no I love you so, yeah

  • 英詞チェックしていただけませんか?

    大変恐縮ですが、 自分なりに頑張って英語の作詞に挑戦してみました。 近くに英語をチェックしてくれる方がいないので、 もしよろしければチェックしていただけませんか? これを発表する日が迫っているので、できれば早めにお願いします。 Brownie I said yes You said NO This is the game of love between us Feel my pain Feel what I feel I wanna ask you why you left me alone I did my best but you didn't do so. I gave everything but you gave nothing What's wrong with you? Am I wrong? I'm thinking of you so much that I can't fall asleep... Oh,what is true love? I'm gonna crazy if you never come back Oh,what is true love? I'm trying to be a better man to ready for meet again... The sun going down,the moon lights the town The loneliness attacks me and makes me sad "I'm alright,I don't care." said while watching TV though which was just a bluff Don't you know why I want you? That's not only your looks but all of you Gimme your love Gimme your kiss I'm thinking of you so much that I can't fall asleep... Oh,what is true love? I'm gonna crazy if you never come back Oh,what is true love? I'm trying to be a better man to ready for meet again... Some birds in the sky are looking down on me as if they show off their freedom Gimme your love Gimme your kiss I suspect that you start to love someone else! No no no... Oh,what is true love? I'm gonna crazy if you never look back Oh,what is true love? I'm trying to be a better man to love you again Oh,what is true love? I'm gonna crazy if you never come back Oh,what is true love? I'm trying to be a better man to love again and again Oh,it's time to go... Oh,it's time to grow... 何かおかしいところなど、アドバイスよろしくお願いいたします。

  • 関係副詞の構文について

    関係副詞を用いて1文にする問題です。 1 Your daughter is coming home next week.   Let me know the day. 2 He was absent today.   I don't know the reason. 1がLet me know the day when your daughter is coming home. 2がI don't know the reason why he was absent today. であってますか? 教えて下さい。お願いします!!

  • 英語に自信のある方、英訳チェックお願いします!

    1、 A "Why is your answer always 'I don't know' and not 'yes'!!"   B "Your answer is always "I don't know". Why not yes?" 「君の答えはどうしていつも“I don’t know” で “Yes” じゃないんだ!!」 (AかBかどちらがよいでしょう?)  2 " I....am afraid. Ah,...I don't want to get pregnant.  I want to you to use birth control." 「 その……、妊娠したくないの。  避妊して欲しいの」 3 " I 've already promised Nana to meet ." 「ナナと会う約束をしてるわ」 日本語に合わせた英文にしたいのですが、これでOKでしょうか? 英語に自信のある方、チェックお願いします。 小説(趣味)に使いたいので、できればネイティブチェックがあればありがたいです。

  • Be Be Your Loveの歌をうたっているRachael Yam

    Be Be Your Loveの歌をうたっているRachael YamagataのRachaelはなんと読めばいいでしょうか? あとSuddenly I Seeの歌をうたっているKT Tunstallはなんと読めばいいでしょうか。 分かるほうを教えてくれればいいです。 よろしくお願いします。

  • お互い母国語が英語ではない男女間のメール文章の一部です

    お互い母国語が英語ではない男女間のメール文章の一部です (連続したものではありません) 恋人同士のやりとりと感じましたが、友人間でもありうる文章なのでしょうか? 男:I love you I want to hear your voice and look your face. I always keep in mind for(名前). I also miss you 女:My friend sent me your conversation, she said you don't love me, you just cheat me. but why did you look so sad? If you are playing with me. I am confused. I don't understand.

  • 英語の会話文から、質問です。

    A: Oh, my God. You're “B”. Hi. I'm “A”. B: Hi. A: Ok. Let me just get this dorky stuff out of the way, ok? I love you. I love your work. I love you and your work. Ok, now I can be my regular hip self. I love you. I love your work. I love you and your work. 『Ok, now I can be my regular hip self.』の部分がさっぱり分かりません。 どなたか解説をお願いします。

専門家に質問してみよう