|
Hi, Euh... what about this (I haven't studied the crazy C coding in detail, but I guess it should do the same). /free S = Line; p = strtok(S: Stop); DoW p <> *Null; n = n + 1; Word(n) = %Str(p); p = strtok(*Null: Stop); EndDo; /end-free Funny to know that strtok() is a C function and isn't used in the provided C code :-) Kind regards, Paul -----Original Message----- From: James Rich [mailto:james@eaerich.com] Sent: 18 April, 2002 21:46 To: rpg400-l Subject: convert this code I need to convert the following C code to RPG. I suppose I can leave the getword() function as C, but I really need to be able to do the main() function as RPG. Some help making this RPG would be great :) #include <stdio.h> void getword (char *word, char *line, char stop) { int i, x, y; for (i = 0; ((line[i] == stop) && (line[i]));) { x = 1; y = 0; while (line[y++] = line[x++]); } for (x = 0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; if (line[x]) ++x; y = 0; while (line[y++] = line[x++]); return; } int main () { char array[] = "This is a test. And so is this."; char *string; string = (char *) malloc (sizeof (char) * (strlen (array) + 1)); printf ("array:\t%s\n", array); while (array[0]) { getword (string, array, ' '); printf ("string:\t%s\n", string); } return (0); } James Rich james@eaerich.com _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l or email: RPG400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ==============================================================================
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.