473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

programme array (scanf inside loop) problem

my programme is to enter numbers of array

it work but it appears to call scanf again first

while it should call ((( 1-printf 2-scanf 3-printf ))) 4-scanf 5-printf 6-scanf 7-printf 8-scanf .......

it work like that call((( 1-printf 2-scanf 3-scanf))) 4-printf 5-scanf 6-printf 7-scanf 8-printf .........

my question : why it to call scanf again first ??


Expand|Select|Wrap|Line Numbers
  1.    #include<stdio.h>
  2.    main()
  3.    { int i=0, first[6];
  4.    while(i<=5){
  5.    printf("enter array [5] number {%d} \n",i+1);
  6.    scanf("%d\n",&first[i]);
  7.    i++;}
  8.    printf("first array content numbers are");
  9.    for(i=0;i<=5;i++){printf("%d\t",first[i]);
  10.    }
  11.    return 0;
  12.    }
Dec 27 '13 #1
1 1256
weaknessforcats
9,208 Expert Mod 8TB
The problem is in the scanf. What you want is to key in a value into the array, then press enter, then key in the next value, press enter, etc.

That means you need to deal with those enter key presses. They need to be got rid of.

So change your scanf to:

Expand|Select|Wrap|Line Numbers
  1.  scanf("%d%*c",&first[i]); 
Now the digits of the value will be put into first[i] and then one more byte will be scanned as a char but the char will not be put into memory. That's what the %*c does.
Dec 27 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: vjay | last post by:
I want to just create a linklist.The program below goes into an endless loop.The srange behaviour is that i can exit from the program if i create only two nodes.After two goes into infinite loop. ...
15
by: Markus Pitha | last post by:
Hi, My program should ask for repeating a calculation or not. I want to solve it with a do..while, but the weird thing is that the program totally ignores the scanf line where I want to receive...
2
by: drdave | last post by:
Hi All, I'm filling an arraylist with other arraylists within a loop and within the first iteration and addition all is fine.. however when I clear my value holding temporary array I lose the...
3
by: Werner | last post by:
Public AtendanceName() As String 'Array to store names Public ix As Integer Public i As Integer Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As...
1
by: Werner | last post by:
#1 Today 08:18 AM Public AtendanceName() As String 'Array to store names Public ix As Integer Public i As Integer
2
by: gkrishgkm | last post by:
how to use printf/scanf inside printf
11
by: balaraja | last post by:
Hi how to print the diagonal elements of a two dimensional array using for loop Can any one help me...Plzzzzzzzz.. Thanks in advance Bala...
4
by: ashashi87 | last post by:
I'm extremely new to perl. I decided to pick it up recently and was writing some elementary code just to get the hang of things. In doing so I've come across a stumbling block for which I couldn't...
3
by: fishnfrogs | last post by:
Hi, I can't figure out why this isn't working. I'm trying to loop through an array and do a mysql update. However, it doesn't work. for($i = 0; $i < $len; ++$i) { $param = $array . '%';...
3
by: Dan Witten | last post by:
Hi, got a question regarding a MySQL database. The database is for tracking online votes. The table is simple: VoteID VoteDate UserName (of person voting) (Then 8 fields of candidates) if...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.