LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in building short input output GUI

Hi
i want to build a program containing 1 input string control, 1 output string control, 3 command buttons;
first- copies input text to output

second- converts input to Uppercase and show it in output "String control"

third - Converts input to lowercase and show it in output "String control"

i was told to use the following functions: strcpy,strcat,strcmp,strlen,toupper,tolower

please help
David
0 Kudos
Message 1 of 5
(2,764 Views)
I don't mind giving you a little help, but I don't want to do your school homework. Especially with C, you need to learn by doing.
The functions you mention are all part of ANSI C. Any ANSI C reference will document them. The CVI function panels for those functions also have help.
An easy way to call up the CVI function panel is to go to any CVI source code window and press P, then enter the name of the function you're interested in. In the function panel, goto Help >> Function.
A couple of CVI functions (non-ANSI C) you'll need are GetCtrlVal to read the value of your input string control and SetCtrlVal to set the value of your output string control.
toupper and tolower work on one character. Treat the string as a character array and use a for l
oop based on strlen to convert the string to upper or lower case one character at a time.
Message 2 of 5
(2,764 Views)
Thanx,
but i still have problems
toupper ,tolower finctions give me strange outputs...
0 Kudos
Message 3 of 5
(2,764 Views)
Your statement
toupper (input[i]);
doesn't give you "strange outputs", you're ignoring the output. Here are some comments.

1. Many C functions return a value. In order to use that value, you need to assign it to a variable or use the function directly in a statement that's looking for a value.
For example, strlen returns an integer, the length of the string passed to it. Here are two ways to use that integer.

int myStringLen, i;
char myString;
strcpy (myString, "Hello World!");
/* save the length of myString to a variable */
myStringLen = strlen(myString);

/* or use strlen directly */
for (i=0; i
2. C functions do not change the value of parameters passed by value. For example, toupper(myChar); doesn't change the value of myChar. See next item.

3. toupper and tolower functions take an input character and return an output character. They do not change the input character. You're ignoring the output character because you don't do anything with the return value. You need to declare an output string and build it byte by byte in the loop.
outputString[i] = toupper(inputString[i]);

4. Take strlen out of your loop. You only need to check the length of the string once: it doesn't change. The way you're using strlen doesn't take the length of the entire string, it only takes the length from where you are (character i) to the end of string.
In C arrays, the first element is 0, not 1. input[1] is the second character, not the first. input[0] is the first.
The way you're using strlen, you never use the length of the string. strlen returns a value. Using it stand alone (without assigning it to a variable or using it as a parameter for a function) does nothing.
Use strlen(input) to end your loop: for (i=0; iYou have reserved 100 bytes for your string, but the string may not be 100 bytes long. There's no need to process 100 bytes if your string is "ABC".

5. For functions that need a pointer to a string, using the variable name directly is the same as getting the address to the first character in the string.
For example:

int i = 0;
GetCtrlVal (panelHandle, PANEL_INPUT, &input[i]);

is the same as

GetCtrlVal (panelHandle, PANEL_INPUT, input);

6. Take SetCtrlVal out of your loop. You only want to update the output after you converted the entire input string.

Do you have a C reference book for your class? I'd start in chapter 1.
Message 4 of 5
(2,764 Views)
thanx alot
from now on I`ll use the book.
0 Kudos
Message 5 of 5
(2,764 Views)