NO

Author Topic: missing swab prototype  (Read 2781 times)

novalis

  • Guest
missing swab prototype
« 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?


Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: missing swab prototype
« Reply #1 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
« Last Edit: August 06, 2010, 12:52:16 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: missing swab prototype
« Reply #2 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;
}
May the source be with you

novalis

  • Guest
Re: missing swab prototype
« Reply #3 on: August 06, 2010, 09:47:18 PM »
Thanks  :)