| 
 | 
Thanks Patrick. Now for the tricky one. I have an external DS which has fields defined in it such as CHAR MSGDTp [40] (The field is actually named MSGDT# however the interface converts the # to p to establish a correct C syntax named field). If I want to append some other string via strcpy then both fields have to be a string (according to the manual). Does this mean that I have to convert my external DS field into a string (via a locally define variable, of the same size as the MSGTp field plus 1 )?by appending a null character? And if so how do I do that? Do I have to get complicated by finding the first blank in MSGDT ( or the first non-blank from right to left, plus 1 )and then placing the null (0x00) value into that character position to turn it into a string?
-----Original Message-----
From:   Patrick Townsend [mailto:townsend@patownsend.com]
Sent:   Wednesday, 21 June 2000 14:38
To:     C400-L@midrange.com; 'C400-L@midrange.com'
Subject:        Re: 
Mike,
char   mychar;        /* this defines a single character, not a string */
char   mystring[6];   /* this defines a string of 6 bytes. it contains 
garbage */
                       /* until you initialize it */
How to compare a character (note the use of single quote):
       if (mychar == '1')
         foo();
How to compare a string (note the use of double quote):
       if (!strcmp(mystring, "hello"))
         foo();
There are other string comparisons. strncmp() compares strings for a given 
number of bytes. stricmp() ignores case on the compare, etc.
If you want to check the value of a single character in a string you can do:
       if (mystring[4] == '1')
          foo();
This checks the fifth position in the string for the character value of '1'.
Strings are not null terminated until you make them so. Some C functions 
will automatically terminate a string with a null. Some examples:
     memset(mystring, 0, sizeof(mystring));    /* sets the entire string to 
nulls */
     strcpy(mystring, "hello");                /* creates a null terminated 
string */
Patrick
At 09:03 PM 6/20/2000 -0400, Pantzopoulos, Mike wrote:
>I'm a bit confused about how to deal with a single character. Is a char 
>x[1]; or char x; statement defining a string or a character?
>
>Ishould it be compared via a ............if(x== '1')  statement or should 
>a strcmp function be invoked? I presume that any definition such as char 
>x[6] defines a string (as null terminated). So is char x[1] defining a 
>null terminated string of length 2 (inclusive of the null character)?
>
---
IBM AS/400 communications, FTP automation, and network security
software and consulting services.
+---
| This is the C/400 Mailing List!
| To submit a new message, send your mail to C400-L@midrange.com.
| To subscribe to this list send email to C400-L-SUB@midrange.com.
| To unsubscribe from this list send email to C400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: bob@cstoneindy.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.