I need to write a method that will load a bitmap image into an array, but whenever I try it doesn't prompt me for the name, and if I type something in there, it will prompt me but will only look at what I typed before, here is the code thus far: - [printf("Enter filename: "); scanf(" %s", &fileName); load(fileName, imgSet, n);
-
void load(char fileName[], unsigned char imgSet[], int n)/*LOADS THE IMAGE FROM A FILE NAME [STATUS: TESTING]*/
-
{
-
readImage(fileName, imgSet[n]);//CALLS THE readImage METHOD FROM bitmap.c FOR THE SIZE OF THE ARRAY
-
if(n<10)
-
{
-
readImage(fileName, imgSet[n]);
-
++n;
-
printf("File %s has %d rows and %d columns\n",fileName, vSize+1, hSize+1);
-
}
-
if(n==10)
-
{
-
n=0;
-
readImage(fileName, imgSet[n]); ++n;
-
printf("File %s has %d rows and %d columns\n", fileName, vSize+1, hSize+1);
-
}
-
menu();
-
}]
Here is another part of the code - [
-
#include <stdio.h>
-
-
#define LENIMG 2+256*256
-
-
typedef unsigned char uchar; /* unsigned type aliases */
-
typedef unsigned short ushort;
-
typedef unsigned long ulong;
-
-
typedef struct { /* bmp header (and info) structure */
-
/* header section */
-
char id[2]; /* must be "BM" */
-
ulong fileSize; /* file size in bytes */
-
ushort reserved[2]; /* reserved (always 0) */
-
ulong totHeadSize; /* total head size (assume 54L=0x36) */
-
/* info section */
-
ulong headerSize; /* header size (assume 40L=0x28) */
-
ulong numCols; /* number of columns in image */
-
ulong numRows; /* number of rows in image */
-
ushort planes; /* number of planes (assume 1) */
-
ushort bitsPerPixel; /* bits per pixel (assume 24) */
-
ulong compression; /* compression (assume 0L=none) */
-
ulong imageSize; /* total pixels in image */
-
ulong xPelsPerMeter; /* x pixels/meter (assume 2925L=0x0b6d) */
-
ulong yPelsPerMeter; /* y pixels/meter (assume 2925L=0x0b6d) */
-
ulong numLUTentry; /* number of LUT used (assume 0L) */
-
ulong impColors; /* number of LUT important (assume 0L) */
-
} BMPHead;
-
-
static ushort getShort(FILE *inf)
-
{
-
char c;
-
ushort ip;
-
c = getc(inf); ip = (ushort)c; /* store lower order byte */
-
c = getc(inf); ip |= (ushort)c << 8; /* store higher order byte */
-
return ip;
-
}
-
-
static ulong getLong(FILE *inf)
-
{
-
char c;
-
ulong ip;
-
c = getc(inf); ip = (uchar)c; /* store lower order byte */
-
c = getc(inf); ip |= (uchar)c << 8;
-
c = getc(inf); ip |= (uchar)c << 16;
-
c = getc(inf); ip |= (uchar)c << 24; /* store highest order byte */
-
return ip;
-
}
-
-
void readImage(const char *fname, unsigned char *img)
-
{
-
FILE *inf; /* input .bmp file */
-
BMPHead h; /* file header */
-
int nRows, nCols, pos;
-
int row, col;
-
int total, gray;
-
uchar r, g, b, x;
-
int pad, p;
-
-
inf = fopen(fname, "r"); /* open file for reading */
-
if (inf == NULL) {
-
printf("File %s: cannot open file for reading\n", fname);
-
exit(1);
-
}
-
-
h.id[0] = getc(inf); h.id[1] = getc(inf); /* read magic number */
-
if (h.id[0] != 'B' || h.id[1] != 'M') {
-
printf("Illegal magic number. May not be a valid .bmp file\n");
-
exit(1);
-
}
-
-
h.fileSize = getLong(inf); /* read file size */
-
h.reserved[0] = getShort(inf); /* (ignored) */
-
h.reserved[1] = getShort(inf); /* (ignored) */
-
h.totHeadSize = getLong(inf); /* total header size (assume 54) */
-
h.headerSize = getLong(inf); /* header size (assume 40) */
-
h.numCols = getLong(inf); /* number of columns in image */
-
h.numRows = getLong(inf); /* number of rows in image */
-
h.planes = getShort(inf); /* number of planes (1) */
-
h.bitsPerPixel = getShort(inf); /* (assume 24) */
-
if (h.bitsPerPixel != 24) {
-
printf("We only support uncompressed 24-bit/pixel images\n");
-
exit(1);
-
}
-
h.compression = getLong(inf); /* (assume 0) */
-
h.imageSize = getLong(inf); /* total pixels in image */
-
h.xPelsPerMeter = getLong(inf); /* (ignored) */
-
h.yPelsPerMeter = getLong(inf); /* (ignored) */
-
h.numLUTentry = getLong(inf); /* (ignored) */
-
h.impColors = getLong(inf); /* (ignored) */
-
-
nRows = h.numRows;
-
nCols = h.numCols;
-
-
if (nRows > 256 || nCols > 256) {
-
printf("Image size is too big\n");
-
exit(1);
-
}
-
-
img[0] = (nRows-1);
-
img[1] = (nCols-1);
-
-
pad = 4*ceil((float)nCols*3/4) - nCols*3;
-
for (row = 0; row < h.numRows; row++) {/* read pixel values */
-
pos = row*nCols + 2;
-
for (col = 0; col < h.numCols; col++) {
-
b = getc(inf); g = getc(inf); r = getc(inf);/* read RGB */
-
total = (int)b + (int)g + (int)r;
-
gray = floor((float)total/3 + 0.5);
-
img[pos++] = gray;
-
}
-
for (p=0; p<pad; p++) x = getc(inf);
-
}
-
fclose(inf);
-
}
-
]
3 1820
Please put your code in tags and make comments explaining your code so I will help.
My code is too long for tabs but here is a sample of it: - {printf("Enter filename: "); scanf(" %s", &fileName); load(fileName, imgSet, n);}/*Loads the image into the array for printing*/
-
-
void load(char fileName[], unsigned char imgSet[], int n)/*LOADS THE IMAGE FROM A FILE NAME [STATUS: TESTING]*/
-
{
-
/*ERROR: ONCE OPTION 'L' IS ENTERED, DOES NOT PROMPT. INSTEAD THE FILE NAME MUST BE TYPED THEN
-
* AND THEN PROMPTED, THOUGH IT WILL USE THE ONE WHICH WAS TYPED WITHOUT BEING PROMPTED*/
-
readImage(fileName, imgSet[n]);//CALLS THE readImage METHOD FROM bitmap.c FOR THE SIZE OF THE ARRAY
-
if(n<10)
-
{
-
readImage(fileName, imgSet[n]);
-
++n;
-
printf("File %s has %d rows and %d columns\n",fileName, vSize+1, hSize+1);
-
}
-
if(n==10)
-
{
-
n=0;
-
readImage(fileName, imgSet[n]); ++n;
-
printf("File %s has %d rows and %d columns\n", fileName, vSize+1, hSize+1);
-
}
-
menu();
-
}
menu and readImage functions are already defined, hope this helps clarify things.
scanf stops scanning when it sees whitespace (like an enter key). It leaves the enter key in stdin. Then the next scanf sees that enter key and quits without fetching anything.
Be sure to fetch that enter key before doinmg the next scanf.
This is based on the fact that scanf is for formatted input. That is, you know at the time you write the code what the inut will be. If you don't know that, then don't use scanf.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: CHANGE username to westes |
last post by:
What are the most popular, and well supported, libraries of drivers for bar
code scanners that include a Visual Basic and C/C++ API? My requirements
are:
- Must allow an application to be...
|
by: TheB |
last post by:
Ok, lets try this again.
I have a program which searches all disk drives for certain file types.
When it finds a file it writes a record to a Firebird DB. The program
normally is using 40 - 44...
|
by: trialproduct2004 |
last post by:
Hi all
I am having problem at a time of handling threading.
I am having application containing thread.
In thread procedure i ma using recursive function.
This recursive function is adding some...
|
by: Mantorok |
last post by:
Hi all
Does anyone here have to use VS on a machine that has "on-access" virus
scanning?
We have Read/Write scanning turned on on our desktops and we're pretty sure
that it is killing VS and...
|
by: deacon57 |
last post by:
FYI - If you are a computer scientist (or geek), this post may be for you.
I wanted to log any search keywords, etc that are used on my site. I created a simple
program that logs search terms...
| |
by: nor |
last post by:
Hi,
I've application to capture video of image and grab the still image. It runs well until I put loop to regrab the still images many times automatically. It gives one exception error:...
|
by: miconib |
last post by:
Hello everyone. I am not really a databse pro like most of you here, but i did make a small access database for our warehouse to scan serial numbers into the system. I have a few questions if anyone...
|
by: kirubagari |
last post by:
For i = 49 To mfilesize Step 6
rich1.SelStart = Len(rich1.Text)
rich1.SelText = "Before : " & HexByte2Char(arrByte(i)) & _
" " & HexByte2Char(arrByte(i + 1)) & " " _
&...
|
by: iheartvba |
last post by:
Hi Guys,
I have been using EzTwain Pro to scan documents into my access program.
It allows me to specify the location I want the Doc to go to. It also allows me to set the name of the document...
|
by: pinkskink |
last post by:
I have a problem using a bar code scanner into a text area.
I found on this forum someone with the same problem as me, except he thought the javascript wasn't finding the <GS> character \1D....
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |