Pelles C forum

C language => Beginner questions => Topic started by: novalis on August 06, 2010, 12:35:45 PM

Title: missing swab prototype
Post by: novalis on August 06, 2010, 12:35:45 PM
Hi,
i just installed pelles c  and wanted to  compile some source.
I've got the following  error:
 warning #2027: Missing prototype for 'swab'.

could find  the include file  in which it is.
Can anybody help?

Title: Re: missing swab prototype
Post by: frankie on August 06, 2010, 12:50:26 PM
Normally swab() is defined in the header string.h, but unfortunately PellesC doesn't include this function in its standard library.
You have to write the function by yourself. An example of source code for it is @http://www.koders.com/c/fid39013354DB227048FD22956E4D3434E8A423114C.aspx?s=strtok+source+code (http://www.koders.com/c/fid39013354DB227048FD22956E4D3434E8A423114C.aspx?s=strtok+source+code)
Title: Re: missing swab prototype
Post by: TimoVJL on August 06, 2010, 05:03:41 PM
Not perfect.

Code: [Select]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void swab(const void *restrict src, void *restrict dst, size_t len);

int main(void)
{
const char *source = "ePllse Csig oo!d"; // len 16
const char *source1 = "hTsii  son t "; // len 13
char target[19];

swab(source, target, strlen(source));
printf("swab(%s) becomes (%s)\n", source, target);
swab(source1, target, strlen(source1));
printf("swab(%s) becomes (%s)\n", source1, target);
return 0;
}

void swab(const void *restrict src, void *restrict dst, size_t len)
{
for (int i = 0; i < len; i += 2) {
*((char*)dst+i+1) = *((char*)src+i);
*((char*)dst+i) = *((char*)src+i+1);
}
*((char*)dst+len) = 0;
}
Title: Re: missing swab prototype
Post by: novalis on August 06, 2010, 09:47:18 PM
Thanks  :)