0

So yeh, I'm kind of new to c :). So, as far as I know, and array initialized to 0 will stay at 0 unless something is stored by some other function or command. so I have and array here(imgSet) that when I tell my program to print out elements individually, its giving some wierd things, depending on how I want them to be printed( i.e. characters, int, etc...)

I can't seem to find any cases where this has happened anywhere else and I wanted to see what some pro's would think about this.

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

int main()
{
	// setting up array and a few integers i may need//
	char imgSet[10][65538] = {0};
	char *filename[80];
	char *menu;
	char l,L,r,R,p,P,a,A,h,H,v,V,t,T,d,D,m,M,q,Q;
	char *menuinput=0;
	int x,i,j,vSize,hSize;
	int control1 = 0;
	int control2 = 0;
	l = 'l';
	L = 'L';
	r = 'r';
	R = 'R';
	p = 'p';
	P = 'P';
	a = 'a';
	A = 'A';
	h = 'h';
	H = 'H';
	v = 'v';
	V = 'V';
	t = 't';
	T = 'T';
	d = 'd';
	D = 'D';
	m = 'm';
	M = 'M';
	q = 'q';
	Q = 'Q';
	menu = ("*****OPTION*****MENU***** \nL: Load image \nR: Remove image \nP: Print image \nA: Average image \nH: Horizontal derivative\nV: Vertical derivative\nT: compute hisTogram\nD: search Digram\nM: local Maxima\nQ: Quit program\n*************************\n\n");
	
	//void readImage(const char *fname, unsigned char *img);
	
	
	while((control1 == 0))
	{
	
	printf("%senter option:",menu);
	scanf("%s", &menuinput);

	if((menuinput == l) ||(menuinput == L))
	{
		printf("Enter filename:");
		scanf("%s",&filename);
		printf("%s\n\n",filename);
		i = 0;
		while (i<10)
		{
			if (imgSet[i] == 0)
			{
				printf("empty %d\n",i);
				i += 1;

			}
			else
			{
				j = i;
				printf("%c ",imgSet[i]);
				printf("j is %i\n",j);
				i += 1;
				
			}
		}
		printf("\n");
		//readImage(filename,imgSet[i]);
				//i = 10;
			
		
	}
	else if((menuinput == 'r') ||(menuinput == 'R'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'a') ||(menuinput == 'A'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'p') ||(menuinput == 'P'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'h') ||(menuinput == 'H'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'v') ||(menuinput == 'V'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 't') ||(menuinput == 'T'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput =='d') ||(menuinput == 'D'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'm') ||(menuinput == 'M'))
		printf("input is %s\n\n",menuinput);
	else if((menuinput == 'q') ||(menuinput == 'Q'))
		printf("Terminating\n\n",control1 = 1);
	else
		;

	}
	





}

When I run this I am putting L as my input and anything as a file name since it isnt reading anything yet. I set it to output something the contents of the array and the index it is in as the j variable.

this is the output it is giving me in its current state.

L j is 0
N j is 1
P j is 2
R j is 3
T j is 4
V j is 5
X j is 6
Z j is 7
\ j is 8
^ j is 9

Help please. Thank you

Edited by jayzee1989: n/a

4
Contributors
8
Replies
12
Views
5 Years
Discussion Span
Last Post by jayzee1989
Featured Replies
  • 2
    Narue 5,707   5 Years Ago

    imgSet is a 2D array, dude. [iCODE]printf("%c ",imgSet[i])[/iCODE] isn't doing what you think it's doing. Read More

0

AHHHH,

ok, I set the logical operator and the print statement with respect to imgSet and its working so far.


Thank you !!!

0

You can simplity all those if statements if you convert menuinput to either upper or lower case. And then you can use a switch statement. You can also delete all those variables on line 11 and initializations on lines 16-33.

menuinput = toupper(menuinput);
switch(menuinput)
{
   case 'A': // blabla
}

Edited by Ancient Dragon: n/a

0

well this is a project for school that stores 10 text based images in a REALLY long array, consisting of 10 images with (2 + 256*256) elements to make up and image. the 2 is for the Height and width of the image, resulting in 65538

0

Use a calculator if you have to but 256*256 = 65536, not 65538.

yes, which would be the max size of the text based image, the other 2 characters are there for the height and width of the image. ex if the 1st 2 characters were 200 and 100, this would have a hieght of 200 pixels and width of 100

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.