Reputation: 17
Take Float Input in a Row With Tabs
I want to take float input from the user a specific number of times in such a way that when the user presses the enter key, instead of going to the next line as scanf() automatically does, move the cursor one tab forward (\t).
Example:
5 -4 8 75
2 -7 4 11
Note: I'm using this code to get float values into an array for matrices.
I have tried a variation of the following:-
int i=0,interval=10;
float a[10]={0};
for (i=0;i<interval;i++)
{
scanf("%f",a[i]);
printf("\t");
i++;
}
OR
int i=0;
float a[10]={0};
while (a[i]=getche()!='\r')
{
printf("\t");
i++;
}
I would really appreciate it if someone helps me out.
Upvotes: 0
Views: 146
Reputation: 339
If you were using windows, you can actually try:
#include <conio.h>
and:
char c[100];
int i = 0;
float f;
while ((c[i++]=getch())!='\t');
c[i++] = '\0';
f = atof(c);
Since getch()
read characters instantly.
Upvotes: 1