#include<stdio.h>
int main()
{
char s[]="123 45.32 4";
int x;
double y;
int c;
puts(s);
sscanf(s,"%d%lf%d",&x,&y,&c);
printf("%d\n%lf\n%d\n",x,y,c);
}
Have a Read!
Sunday, February 6, 2011
How to use sscanf
How to use sprintf
#include<stdio.h>
int main ()
{ int x;
char s[80];
double y;
printf("ENTER\n");
scanf("%d%lf",&x,&y);
sprintf(s,"integer:%6d\ndouble:%.2f\n",x,y);
puts(s);
}
How to get string input way2
#include<stdio.h>
int main ()
{ int i=0;
char c;
char a[80];
printf("ENTER\n");
while ((c=getchar())!='\n') {a[i++]=c;}
a[i]='\0';
puts(a);
}
How to get a string input way1
#include<stdio.h>
int main()
{
char s[50];
printf("enter\n");
fgets(s,50,stdin);
printf("%s",s);
}
How to use strtol
#include<stdio.h>
#include<stdlib.h>
int main () {
const char *string="21.3% are good" ;
long d;
char *stringptr;
d=strtol(string,&stringptr,0);
printf("%s\n%ld\n%s\n",string,d,stringptr);
}
How to use strod
#include<stdio.h>
#include<stdlib.h>
int main () {
const char *string="21.3% are good" ;
double d;
char *stringptr;
d=strtod(string,&stringptr);
printf("%s\n%.2f\n%s\n",string,d,stringptr);
}
How to use atol
#include<stdio.h>
#include<stdlib.h>
int main() {
long i;
char s[20]={"23.56 this is"};
i=atol(s);
printf("%ld\n",i);
}