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

Help skipping an element when printing an array in C

Hi,

I have to write a slide puzzle program for class. I have the program finished and working except that I can not get the blank space to print out. I wrote code that would find the number I used for the blank space. I have the puzzle print out using two for loops, then before the line that prints it I used an IF statement to find the number. I have tried using a break statement, but it does not finish the rest of the for loop for the columns. I also tried to have it print then used the backspace in an attempt to delete it. When I do that and swap the blank space with the number on the left a few times it distorts the puzzle. I tried to advance the column when it finds the number I want to skip but can not get the numbers to move around. We are getting into to pointers on the next lesson so I know I can not use them. I tried to change the array to character but that did not work either. When I leave the number in that I used for a blank space, which is 100, the program works great.

Expand|Select|Wrap|Line Numbers
  1. void print(){
  2.      printf("\n");
  3.      int i=0;int j=0;
  4.      for (i=0;i<4;i++){
  5.         for (j=0;j<4;j++){
  6.          puzzle[i][j]; 
  7.          if (puzzle[i][j]==100)                                 
  8.                                 j=j+1;  /*This was the last attempt.*/
  9.  
  10.         printf("%d\t", puzzle[i][j]);
  11.         }
  12.         printf("\n");
  13.         }
  14.         printf("\n");
  15.         }
This is the code from the function that I created to print the array out. I have racked my brain over this for days now and need some help.

Thank you for taking a look.
Oct 11 '07 #1
2 1899
DumRat
93
Did you try using the "continue" keyword? if it is the blank square, print a space and continue.
Oct 11 '07 #2
Thanks,

It is now working. Inside the if statement I inserted a space and tab right before the continue and it is working. The funny thing is I tried the continue before just not like that. Thank you I knew it had to be something simple I was overlooking I just could not figure it out.
Oct 11 '07 #3

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

Similar topics

9
by: Ken | last post by:
I have a small program , wi tha menu (only option 1,2 and 6 are working for now) Something weird is happening, my array works to input all the data the user puts in, but whebn I choose option 2,...
16
by: Simon | last post by:
I am a programming student and have recently missed two weeks of school due to a serious injury in a car accident. I am completing all of my assignments (via Labs) but have come across the...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
0
by: silvrique | last post by:
I am totally lost. I have an xml script example as follows: <?xml version="1.0" encoding="utf8" ?> <starter> <second> <name>Silver</name> </second> </starter>
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: Latina | last post by:
Hi, Can some one help to figure out why is only printing '{ }' and not the values the user is entering? Here is part of my code: void IntegerSet::setString() { cout<<"{"; for(element=0;...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.