Taz bisounours-codeur | exemple rapide C99
Code :
- #include <string.h>
- inline void swap(void * restrict const a,
- void * restrict const b,
- const size_t size)
- {
- char buffer[size];
- memcpy(buffer, a, size);
- memcpy(a, b, size);
- memcpy(b, buffer, size);
- }
- void reverse(void * const t, const size_t nmemb, const size_t size)
- {
- char * const p = t;
- for(size_t i=0; i < nmemb/2; ++i)
- {
- swap(p + i*size, p + (nmemb-i-1)*size, size);
- }
- }
- #include <stdio.h>
- int main()
- {
- char taz[] = "TazForEver";
- puts(taz);
- reverse(taz, sizeof taz - 1, 1);
- puts(taz);
- }
|
|