To print a C string, use %s, not %c.
Edit: You might also want to put a newline \n at the end.
Printable View
To print a C string, use %s, not %c.
Edit: You might also want to put a newline \n at the end.
Thanks a lot.. I'll try it right now..
It works right.. Thanks a loott.... :D.........
Erhm, look carefully, it should be obvious, if you *really* cannot see it, ask again
by the way, telnum does not have to be an array, that just makes it harder.
It will work fine as an ordinary int.
Or, if you are picky and want the '-' in the number, you should have a string.
Important thing here.
You missed
Code:#include <strings.h>
it's string.h.
nothing is used that's in string.h
You should be using fgets(), not gets().
oki.. well can anyone cheK this out for me, I'm havin errors[well dnt blame me coz i havent yet bought a book on c prog..tomoro wil do it..]:
Code:/* Program 2 */
#include <stdio.h>
#include <string.h>
int main(void)
{
char name;
float weight;
float height;
printf("Enter your name:");
fgets(name);
printf("Enter your height in metres:");
fgets(height);
printf("Enter your weight in Kg");
fgets(weight);
printf("\n Personal Details:");
printf("\n Name:%s",name);
printf("\n Height in m: %s",height*100);
printf("\n Weight in Kg: %s",weight/1000);
return 0;
}
How about, instead of dumping code on us, you actually take the time to tell us the exact errors?
Or better, yet, why not research how to use fgets() on your own?
Here's the FAQ entry on why gets() should not be used, and how to use fgets() (at the very bottom it shows an fgets() line for the supplied program):
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
for a reference on functions see:
http://www.cplusplus.com/
http://www.cplusplus.com/reference/c...dio/fgets.html
%f is data type descriptor for floatCode:#include <stdio.h>
#include <string.h>
int main(void)
{
char name[20];
float weight;
float height;
printf("Enter your name:");
scanf("%s",name);
printf("Enter your height in metres:");
scanf("%f",&height);
printf("Enter your weight in Kg");
scanf("%f",&weight);
printf("\n Personal Details:");
printf("\n Name:%s",name);
printf("\n Height in m: %f",height*100);
printf("\n Weight in Kg: %f",weight/1000);
return 0;
}
%s for string
%d for integer
many other are there
dont confuse with them
char name;
this allocates only one byte so it stores only one chatacter
so use array for name