Discuss Input taking spaces by default in the C Programming forum on Dev Shed. Input taking spaces by default C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Posts: 27
Time spent in forums: 8 h 7 m 21 sec
Reputation Power: 0
Input taking spaces by default
In the below program when am reading input from keyboard its taking only 2 characters instead of 4 and remaining 2 characters its taking spaces by default.
why is it???
// reversestring.cpp : Defines the entry point for the console application.
//
Code:
/*program to take char input through pointers*/
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
int _tmain(int argc, _TCHAR* argv[])
{
int c,inc,arrysize;
char *revstring;
printf("enter the size of char arry:");
scanf("%d",&arrysize);
revstring = (char *)malloc(arrysize * sizeof(*revstring));
printf("%d",sizeof(revstring));
printf("enter the array elements:");
for(inc=0;inc<arrysize;inc++)
{
scanf("%c",&revstring[inc]);
}
for(inc =0;inc<arrysize;inc++)
printf("%c",revstring[inc]);
getch();
return 0;
}