Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

ok in C++ i have a class assignment that i need to do and i dont fully understand how to work array's and strings. here is the assignment[ Create a process that accepts a specified string and presents an output in the form a string. Use arrays for the possible outputs and then present the output on screen. Meaning you should have outputs predefined and be calling the variables for the outputs]

OpenStudy (anonymous):

it is supposed to accept a string enter random words( 1,2,3) - - - outputs a variable user arrays for the output strings

OpenStudy (anonymous):

if someone could help it would be greatly appreciated

OpenStudy (anonymous):

do you have sample input and output?

OpenStudy (anonymous):

it has to be a word that leads to a definition

OpenStudy (anonymous):

what is your high level plan?

OpenStudy (anonymous):

if you could split the program into tasks, what are the tasks?

OpenStudy (anonymous):

1 what is an array then the defintion 2 what is a character then a character 3 what is a string the the defintion i belive that answers your question if it does not can you give me an example

OpenStudy (anonymous):

this is all i have done on this assignment #include <stdio.h> int main (void) { char string [] = "arrays"; size_t i;

OpenStudy (anonymous):

ok i have extended this a little bit im still not sure its right or if i am doing this correctly #include <stdio.h> #define SIZE 20 int main (void) { char string1 [] = "arrays"; char string2 [ size_t i; if ( string1 = "grade" ){ puts( "A particular level of rank, quality, proficiency, intensity, or value" ); } if ( string1 = "network" )

OpenStudy (anonymous):

i dont think i need char string 2

OpenStudy (anonymous):

a character is a datatype for storing a single letter.

OpenStudy (anonymous):

it can store a, b, c, etc.

OpenStudy (anonymous):

it is the size of a byte

OpenStudy (anonymous):

an array is a group of variables. every variable in the group has the same data type. every variable in the group has an index, so you can access them individually

OpenStudy (anonymous):

a string is a collection of characters. Usually you use an array to store the collection.

OpenStudy (anonymous):

here is how i think it needs to look #include <stdio.h> #define SIZE 20 int main (void) { char string1 [SIZE]; size_t i; printf("%s", "enter the words grade, network, or computer to find their definitions" ); scanf( "%10s", string1 ); if ( string1 = "grade" ){ puts( "A particular level of rank, quality, proficiency, intensity, or value" ); } else if ( string1 = "network" ){ puts( "An arrangement of intersecting horizontal and vertical lines." ); }

OpenStudy (anonymous):

Don't compare string with `string = "network"`. That won't work. You'll need to compare them character by character. You can use `strcmp()` or you can use a `for` loop.

OpenStudy (anonymous):

ok so i need to use for ( i = 0; i < SIZE && string1[ i ] != '\0'; ++i ) { printf( "%c", string1 [ i ] );

OpenStudy (anonymous):

At the beginning do something like: ``` char[] NETWORK = "network"; int equal; ``` When when you want to compare the string: ``` equal = true; for (i = 0; string1[i] != '\0' && NETWORK[i] != '\0'; ++i) { if (string1[i] != NETWORK[i]) { equal = false; } } if (equal) { // they're equal! } ```

OpenStudy (anonymous):

Hmm, that code isn't correct.

OpenStudy (anonymous):

``` equal = true; for (i = 0; string1[i] != '\0' || NETWORK[i] != '\0'; ++i) { if (string1[i] != NETWORK[i]) { equal = false; break; } } if (string1[i] != NETWORK[i]) { equal = false; } if (equal) { // they're equal! } ```

OpenStudy (anonymous):

the best thing to do though, is to use `strcmp` from cstring library

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!