Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How do I use swab( ) in my program ?

Answer: The function swab( ) swaps the adjacent bytes of memory. It copies the bytes from source string to the target string, provided that the number of characters in the source string is even. While copying, it swaps the bytes which are then assigned to the target string.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

main ( )
{
char *str1 = "hS eesll snsiasl not eh es as oher " ;
char *str2 ;
clrscr( ) ;
swab ( str1, str2, strlen ( str1 ) ) ;
printf ( "The target string is : %sn", str2 ) ; // output -- She sells
snails on the sea shore
getch( ) ;
}

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook