473,386 Members | 1,754 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,386 software developers and data experts.

How to limit the number of integers inputted by the user ?

16
I'm writing a pretty simple program, but I faced a problem in limiting user input data. For example, if I have a 2D-array of a certain size and I asked the user to input the array column by column but the problem is when I run the program it mix the numbers together.
what I actually need is to delete the rest of numbers which are not part of this column so if the size=3 and the user input 1 2 3 4 5 I need the program to skip 4 & 5 and ask the user again to input the next column with different numbers so 4 & 5 will not be printed in the next column (they should be skipped). I have an idea of splitting the loops I mean Inputting the first column in a loop, then another loop for the second column, and so on, but imagine that the size is 100 it will be really long.

This is the program I'm getting a strange output !.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define size 3
  4. int main(){
  5.  
  6.  
  7. int a[size][size];
  8.  
  9. int i,j=0;
  10.  
  11.  
  12.     //printf(" input  column  #%d \n",j+1);
  13.        printf(" input  the first column \n"); 
  14.      for(i=0;i<size;i++){
  15.             scanf("%3d", &a[i][0]);
  16.    if(i==size)
  17.   scanf ("%*[^\n]"); (void) getchar ();
  18.         }
  19.        j++;
  20.          printf(" input  the next column \n"); 
  21.  
  22.            for(i=0;i<size;i++){
  23.             scanf("%3d", &a[i][1]);
  24.    if(i==size)
  25.  scanf ("%*[^\n]"); (void) getchar ();
  26.         }
  27.  
  28.          printf("Matrix A is\n");
  29.     for(i=0;i<size;i++)
  30.     {
  31.        for(j=0;j<size;j++) 
  32.         printf("%d\t",a[i][j]);
  33.         printf("\n");
  34.     }
  35.  
  36.      return 0;
  37. }
May 22 '14 #1
0 1194

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

Similar topics

0
by: gregor | last post by:
Hello I was searching information how to limit space for the user ... eg. user account will be have 5MB space to database. -- darmowa poczta, WWW+PHP, 45MB, bez ograniczeń...
2
by: Dalan | last post by:
I am finalizing an Access 97 db and need to decide was is the best method to limit the number of records one can enter in the demo version of same. The archives seem to be replete with many...
2
by: Ian | last post by:
Using Access 97 I want to distribute my database over a LAN but limit the number of PC's that can use it at the same time. Perhaps limit it to 3 so when the 4th user tries to open it they cant...
1
by: ashokingroups | last post by:
Hi In my program, I need to print the current number of active users at this website, means How many number of people are currently accessing the website. Can anyone please tell the solution: How...
2
by: mktselvan | last post by:
Hi, Existing running oracle application 11i (11.5.8) Database version is 8.1.7.4 There is any command / way to know the number of concurrent users for this application. ...
3
juve11
by: juve11 | last post by:
hello, i have a vb application that writes into mysql (some kind of autocomplete). problem is that it writes too many rows and the app at a moment starts to run slowly.so an option that i thaught...
4
by: ghjk | last post by:
I have php web application and there I have php page for entering stations(Like user). But I want to limit the Number of records. User can only enter the 30 records. How can I limit that?
1
by: vikrant 1993 | last post by:
Write a program to accept a number from the user and display all the prime numbers from one upto the number entered by user.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.