| | |
Copying words into an array of char ?!?
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hey guys,
I really appreciate the effort and time you take out to help me become a better coder :!: I know I'm not the best and it takes alot of time, but, I'm having so much fun in learning this(even if they are simple programs).
I also, worked out the pseudo code WaltP gave me and turned it into this:
I think it differs abit from the pseudo code he gave me, but, it works perfectly. In his pseudo code, he mentions to loop from first to last minus one, wich I "think" means this:
I really appreciate the effort and time you take out to help me become a better coder :!: I know I'm not the best and it takes alot of time, but, I'm having so much fun in learning this(even if they are simple programs).
I also, worked out the pseudo code WaltP gave me and turned it into this:
C Syntax (Toggle Plain Text)
#include <iostream> int main() { char words[5][10]; for (size_t i = 0; i < 5; ++i) std::cin >> words[i]; std::cout << std::endl; for (size_t i = 0; i < 5; i++) { bool contr = true; for (size_t j = i+1; j < 5; j++) { if(strcmp(words[i], words[j]) == 0) { contr = false; break; } } if(contr == true) std::cout << words[i] << '\n'; } std::cin.ignore(2); return 0; }
I think it differs abit from the pseudo code he gave me, but, it works perfectly. In his pseudo code, he mentions to loop from first to last minus one, wich I "think" means this:
for (size_t i = 0; i < 4; i++). But, that doesn't seem to work for me. •
•
•
•
Yes I would ask you to compulsorily make the change.
Normally the strcmp( ) returns -1 , 0 or 1.
The ans is -32
The ans is -1
The ans is -2
using Borland 5.5
So some compilers convert the returns to -1/0/1, others just use the difference between the characters:
'A' - 'a' = 32
'c' - 'd' = -1
'b' - 'd' = -2
So definitely just use <|=|> 0
•
•
•
•
I also, worked out the pseudo code WaltP gave me and turned it into this:
<snip code>
I think it differs abit from the pseudo code he gave me, but, it works perfectly. In his pseudo code, he mentions to loop from first to last minus one, wich I "think" means this:for (size_t i = 0; i < 4; i++). But, that doesn't seem to work for me.
My loops were a little off. The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: Linker info
- Next Thread: Deleting characters function ( with just one parameter)
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






