Computer Science Canada char array problem |
Author: | ynotpeace [ Wed Dec 09, 2009 3:47 pm ] | ||
Post subject: | char array problem | ||
What is it you are trying to achieve? this code uses char arrays to get letters then prints it back to you without any spaces What is the problem you are having? no matter what number of letters i type it only gives back 2 letters ![]() Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) heres the code
Please specify what version of Turing you are using 4.1.1 |
Author: | mirhagk [ Wed Dec 09, 2009 4:02 pm ] | ||
Post subject: | RE:char array problem | ||
use that to quit the first loop instead, (it will fix it) |
Author: | ynotpeace [ Wed Dec 09, 2009 4:13 pm ] |
Post subject: | Re: char array problem |
why do i have to click enter twice to exit loop??? can you somehow make it once? |
Author: | TheGuardian001 [ Wed Dec 09, 2009 4:16 pm ] |
Post subject: | Re: char array problem |
You need to hit enter twice because you are using get to receive input. get requires that you press enter before anything is actually stored, which is ideal for strings, but horrible for character arrays representing a string. Since you're getting it as a character array, I'd advise you use getch, which will get a single character without waiting for enter to be pressed. |
Author: | mirhagk [ Wed Dec 09, 2009 4:22 pm ] | ||||
Post subject: | RE:char array problem | ||||
its because your using get you should use the getch command first declare a string of 1 variable
then getch the letter from the user and assign it to the array (i also put the value so that it shows on screen)
|
Author: | ynotpeace [ Wed Dec 09, 2009 4:23 pm ] |
Post subject: | Re: char array problem |
does getch work with "array of char"??? cause: getch (word1(i)) doesn't work... |
Author: | mirhagk [ Wed Dec 09, 2009 4:24 pm ] |
Post subject: | RE:char array problem |
getch doesnt work with char. it only works with string(1) type (btw that means a string with a length of 1, which is basically a char and char can be assigned to it and vice versa) |
Author: | ynotpeace [ Wed Dec 09, 2009 4:49 pm ] |
Post subject: | Re: char array problem |
sorry about being a pain but i'm really trying to get this but heres the question i'm trying to solve: Problem Description An anagram is a word or a phrase formed by rearranging the letters of another phrase such as ?ITEM? and ?TIME?. Anagrams may be several words long such as ?CS AT WATERLOO? and ?COOL ASWET ART?. Note that two phrases may be anagrams of each other even if each phrase has a different number of words (as in the previous example). Write a program to determine if two phrases are anagrams of each other. Input Specifications The program should prompt the user for two phrases, each entered on a separate line. You may assume that the input only contains upper case letters and spaces. Output Specifications The program will print out one of two statements: ?Is an anagram.? or ?Is not an anagram.? Sample Prompting and User Input (user input in italics) Inputs: Enter first phrase> CS AT WATERLOO Enter second phrase> COOL AS WET ART Output: Is an anagram. |
Author: | mirhagk [ Wed Dec 09, 2009 5:01 pm ] |
Post subject: | RE:char array problem |
just get repeat the first loop for the second phrase then you can compare the two strings. there's several ways of doing this first check to see if the lengths are the same, if not then theyre obviously not anagrams then you could either count the amount of each letter in each array and see if they are the same OR you could convert the arrays to strings then go through each letter seeing if it exists in the other string (remove it from that string if it does exist) |
Author: | ynotpeace [ Wed Dec 09, 2009 5:06 pm ] |
Post subject: | Re: char array problem |
thx guys |