Questions for: Library Functions
#include<stdio.h>
int main()
{
char str[] = "ExamAdept";
printf("%.#s %2s", str, str);
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
char str1[] = "Learn through ExamAdept\0.com", str2[120];
char *p;
p = (char*) memccpy(str2, str1, 'i', strlen(str1));
*p = '\0';
printf("%s", str2);
return 0;
}
Declaration:
void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest
With memccpy(), the copying stops as soon as either of the following occurs:
=> the character 'i' is first copied into str2
=> n bytes have been copied into str2
Discuss About this Question.
#include<stdio.h>
int main()
{
fprintf("ExamAdept");
printf("%.ef", 2.0);
return 0;
}
Declaration Syntax:
int fprintf (FILE *stream, const char *format [, argument, ...]);
Example:
fprintf(filestream, "%s %d %s", Name, Age, City);
Discuss About this Question.
#include<stdio.h>
int main()
{
int i;
char c;
for(i=1; i<=5; i++)
{
scanf("%c", &c); /* given input is 'a' */
printf("%c", c);
ungetc(c, stdin);
}
return 0;
}
for(i=1; i<=5; i++) Here the for loop runs 5 times.
Loop 1:
scanf("%c", &c); Here we give 'a' as input.
printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement.
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
Loop 2:
Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function.
printf("%c", c); Now variable c = 'a'. So it prints the character 'a'.
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
This above process will be repeated in Loop 3, Loop 4, Loop 5.
Discuss About this Question.
The gcvt() function converts a floating-point number to a string. It converts given value to a null-terminated string.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char str[25];
double num;
int sig = 5; /* significant digits */
/* a regular number */
num = 9.876;
gcvt(num, sig, str);
printf("string = %s\n", str);
/* a negative number */
num = -123.4567;
gcvt(num, sig, str);
printf("string = %s\n", str);
/* scientific notation */
num = 0.678e5;
gcvt(num, sig, str);
printf("string = %s\n", str);
return(0);
}
Output:
string = 9.876
string = -123.46
string = 67800
Discuss About this Question.
Discuss About this Question.