>>>I have a simple programming assignment I'm trying to help my daughter with, but I'm a helpless FoxPro addict and I'm not sure how to do this in C.
>>>
>>>She needs to write a loop to parse a string backwards, so 'Hello World' becomes 'dlroW olleH' and so on. Very simple, I could do it in my sleep in Fox, but I'm awake and I don't know much about C.
>>>
>>>Thanks,
>>
>>In C or C#?
>>
>>C#:
>>
>>
>> string source = "Hello World";
>> string result = String.Empty;
>> char[] srcArray = source.ToCharArray();
>>
>> int i;
>>
>> if (srcArray.Length > 0)
>> {
>> for (i=srcArray.Length-1;i>-1;i--)
>> {
>> result += srcArray[i];
>> }
>> }
>>
>>
>>Straight C is a little more code. You have to use the string library (and header).
>
>Keith,
>
>Just in case I don't receive a reply from her regarding C-version, can you outline the same procedure in straight C?
>
>Thanks,
>
>Irv.
I can get you close. I don't have access to a C compiler at work so there may be an error or two.
#include <string.h>
char *source = "Hello World";
int slen = strlen(*source);
char result[slen+1];
int i;
if (slen > 0)
for (i=0;i<=slen;i++)
result[i] = source[slen-i];