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

How do I limit storage in the arrays so that not so many incorrect things print?

typedef int bool;

#include <stdio.h>
#include <string.h>

#define true 1
#define false 0

#define SIZE 25

void fill(char ARRAY[][SIZE], int ROW, int COLUMN);

main()
{
char ARRAY[SIZE][SIZE];
int i = 0, j, strln = 0;
int num1 = 0, num2 = 0;
bool wasPrinted = false;

printf("This program outputs a filled version of a shape that you enter.\nThe largest grid size is %d by %d.\n\n", SIZE,SIZE);
printf("Please enter a point in your shape where you would like to begin filling:\n");
printf("width = ");
scanf("%d", &num1);
printf("length = ");
scanf("%d", &num2);

printf("Please enter your shape outline now, using the * character\n");
gets(ARRAY[i]);

while (i < SIZE)
{
if (strcmp(gets(ARRAY[i]), "") == 0) break;
strln = (strlen(ARRAY[i]) > strln) ? strlen(ARRAY[i]) : strln;
i++;
}

fill(ARRAY, (strln / 2) - 1, (i / 2) - 1);

for (i = 0; i < SIZE; i++)
{
wasPrinted = false;
for (j = 0; j < SIZE; j++)
{
if (ARRAY[i][j] >= 32)
{
wasPrinted = true;
printf("%c", ARRAY[i][j]);
}
}
if (wasPrinted) printf("\n");
}
printf("\n");
system("pause");
}

void fill(char ARRAY[][SIZE], int num1, int num2)
{
int fillL, fillR, i;
int in_line = 1;

fillL = fillR = num1;
while (in_line)
{
ARRAY[num2][fillL] = '*';
fillL--;
in_line = (fillL < 0) ? 0 : (ARRAY[num2][fillL] == ' ');
}
fillL++;

in_line = 1;
while (in_line)
{
ARRAY[num2][fillR] = '*';
fillR++;
in_line = (fillR > SIZE - 1) ? 0 : (ARRAY[num2][fillR] == ' ');
}
fillR--;

for (i = fillL; i <= fillR; i++)
{
if (num2 > 0 && ARRAY[num2 - 1][i] == ' ')
{
fill(ARRAY, i, num2 - 1);
}
if (num2 < SIZE - 1 && ARRAY[num2 + 1][i] == ' ')
{
fill(ARRAY, i, num2 + 1);
}
}
}
Nov 4 '11 #1
2 1935
johny10151981
1,059 1GB
Set 0 value at the end of the textstring.
Nov 4 '11 #2
@johny10151981
Okay, so I void ARRAY?
Nov 4 '11 #3

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

Similar topics

2
by: Afkamm | last post by:
Hi, :) The preg_replace function... preg_replace(pattern, replacement, subject ) How on earth do you get the limit value to work with arrays? In my code both the pattern and replacement...
14
by: Stainless | last post by:
I have a public class Globals, which obviously holds all my global data. I have an array of 243 items, currently structs of type typedef struct STAR { int x; int y; int stellar_class;...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
2
by: arnuld | last post by:
i do not have any problem here. i solved the problem but i wanted to know the views of you. please look at it from a newbie's perspective: problem: define a table with names of months of the...
64
by: Zytan | last post by:
I know there are no pointers in C#, but if you do: a = b; and a and b are both arrays, they now both point to the same memory (changing one changes the other). So, it makes them seem like...
1
by: Nor farhana yaakub | last post by:
hye,i try to implement this program,which is to keep track of no ofstudents together with their marks.i suppose that maximum no of students is 40.and i stored all the input in farhanafiona.txt and i...
6
by: ken | last post by:
is there a way to make a php page only output content that is generated from php statements, such as print, or echo? ie: if I have whitespace (or other text) outside my <?php .... ?block i do not...
3
by: quemix | last post by:
Hi all: I have defined a structure (bit field) like this: struct bit_test { int a:4, b:8, c:20; }; struct bit_test test;
0
by: recruiterforitjobs | last post by:
Hi, Hope you are doing great, My name is Sumit Kumar, and I am a technical recruiter for Okaya Inc, a technical staff augmentation firm located in NY. I am currently in search of an...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.