![]() |
|
#1
|
|||
|
|||
My first thread and i hope that u help me ^_^Hi all.
This is my first participation here, in this perfect forum. first of all, I'm a student in comp. science and I'm still a bigginer in programming. I'm facing some problems in strings and i hope that u'll help me. here i have some problems : How can i read a paragraph from a file then allow the user 2 edit it ?? I mean by editing that how can i allow him 2 add, remove or modify a word !!!! one more thing .. how can i print on the screen the following (( total numbers )) : • Characters (All) • Words • Lines • Spaces • Commas • Full stops what i think that we can print all these by declaring a counter 4 each one, but the main problem that i faced is how 2 read it from a file correctly ?? I hope that u understood me ^_^ Waiting 4 ure replies ..!! |
|
#2
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^Welcome Comp_Lover,
It would be easier if you could post what you have so far or what you have tried. That way the help that is offered can be tailored for the approach you had in mind. |
|
#3
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^This is all what i did.
Really i'm bad in strings. ------------------------------------------------------ CPP / C++ / C Code:
And the problem is in an attachment .. Last edited by admin : 06-May-2006 at 06:54.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#4
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^For simplitcty and testing at this stage I have removed some code so that it can be added back in stages. So we have this.
CPP / C++ / C Code:
CPP / C++ / C Code:
Let us take a look at how to get the "size" of a char array. One way is to use "strlen" from #include <cstring>. CPP / C++ / C Code:
CPP / C++ / C Code:
So that will let you setup your "for loop" and give you the answer to "Characters (All)". So the next step would be to set that up and go from there by adding back stuff one thing at a time making sure they work as expected before adding more code. I know this is does not answer all your questions. But we have to start some place. Post any updated code and any error messages if there are any. |
|
#5
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^Helle mr. Sokar
This is all what i did. please check it. CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^void spaceCounter( char spaces [1000] )
{ int counterOfSpaces =0; for ( int i=0; i<1000; i++ ) { if ( spaces[i] == '\0' ) ++counterOfSpaces; } cout << setw(11) << counterOfSpaces << " spaces" << endl; } I think the space character is ' ' not '\0'. Isnt '\0' the NULL character. |
|
#7
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^void wordCounter( char words[1000] )
{ int counter=0; char *stringPtr; stringPtr = strtok(words," "); while (stringPtr!=NULL) { stringPtr = strtok(NULL," "); counter++; } cout << setw(11) << counter << " words" << endl; } I think also for word count, what if the person enter two or more consecutive spaces like: "I(3 spaces)am" versus "I(1 space)am" think we need to examine the current and either (a) increment if the current is a space && decrement if the previous was a space. or (b) increment if the current is a space && decrement if the next is a space.' or (c) increment only if the next character is not a space or comma or fullstop or question mark .... you get the idea. Am sure we dont want to count "I am a boy. . . ." and count the .'s as words. Ofcourse we would have to make sure when looking at the next or previous our bounds are safe. |
|
#8
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^Quote:
CPP / C++ / C Code:
So what might be a solution? One might immediately think this. CPP / C++ / C Code:
You could start testing with something like this maybe. CPP / C++ / C Code:
"Hi all. This is my first participation here, in this perfect forum. first of all, I am a student in comp. science and I am still a bigginer in programming." Without the quotes. Get that to work and we can take a look at the rest. Post any updated code and any error messages if there are any. |
|
#9
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^I apologize for not including the C++ tags......... I jut learned of how to do it couple moments ago from WaltP
|
|
#10
|
|||
|
|||
Re: My first thread and i hope that u help me ^_^CPP / C++ / C Code:
|
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to protect single thread in phpBB | iota | MySQL / PHP Forum | 0 | 20-Mar-2006 22:48 |
| Sending message to GUI thread that ISNT the main thread | mpviii | MS Visual C++ / MFC Forum | 1 | 20-Apr-2005 12:49 |
| reading from comm port and displaing in editbox using MFc | ib_alam | MS Visual C++ / MFC Forum | 9 | 02-Feb-2005 18:57 |
| The Official Birthday Wishes thread for jrobbio | JdS | Open Discussion Forum | 8 | 20-Nov-2003 18:21 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The