Decimal Values & ANSI C Code for Image File

In summary, the conversation is about how to code in ANSI C to read and process data from a file. The suggested solution is to use the scanf function and write separate functions for different tasks, such as reading the header line and data lines. This will make it easier to write the main loop for processing the data.
  • #1
brad sue
281
0
Hi, I have a problem to code this:

Image that you have the following file presenting the following decimal values:

2 A 40.0
115.00 1.02842 5.944 10.0528 -1.656
115.00 1.01911 4.678 10.0528 177.078

11 6 100.0
115.00 1.01530 2.392 2.9097 11.933
115.00 1.00338 2.849 0.2633 37.685
115.00 1.00566 2.460 1.5274 8.387
230.00 0.99738 5.209 4.3274 -2.728

How can I code in ANSI C so that the program reads the first line, prints it ( I know this part) then reads the following 5 ( which are the values for voltages) add all of them, then goes to to the second ste of five data.

After thatthe program reads the second set of three data, print them, and reads the follwoing five, add them all and so forth.

can some help me or give me some suggestions
Thank you

B
 
Technology news on Phys.org
  • #2
Do you know how to use the scanf function?

For the first line you can do:

scanf("%d %c %f",&a, &b, &c) ;

Then for the the rest of the lines you have a for loop that does this:

scanf("%f %f %f %f %f",&d, &e, &f, &g, &h) ;
 
  • #3
dduardo said:
Do you know how to use the scanf function?

For the first line you can do:

scanf("%d %c %f",&a, &b, &c) ;

Then for the the rest of the lines you have a for loop that does this:

scanf("%f %f %f %f %f",&d, &e, &f, &g, &h) ;

Thank you
My problem was where to start the loop.
 
  • #4
brad sue said:
can some help me or give me some suggestions
My suggestion is that you write separate functions for each separate task, which helps make everything much clearer. For example, write function "readHeaderLine" to process the top line of each data set and write function "readDataLine" to read and process each data line. If these functions return a value like the number of items processed then you can make them return 0 when they come across an empty line. This way your main function will know when a data set is finished (readDataLine has returned 0) or when there is no more data sets to process (readHeaderLine has returned 0). Using these accessory functions, you will find it simple to write the main loop.
 

Related to Decimal Values & ANSI C Code for Image File

1. What are decimal values in ANSI C code for image files?

Decimal values in ANSI C code for image files represent the numerical values assigned to each pixel in an image. These values are typically encoded in the form of RGB (red, green, blue) values, with each color component being assigned a number between 0 and 255. These values determine the color and brightness of each pixel in the image.

2. How are decimal values used in ANSI C code for image files?

Decimal values are used in ANSI C code for image files to represent the color and brightness of each pixel in an image. These values are typically stored in arrays or matrices, with each element representing a pixel in the image. By manipulating these values, different effects and transformations can be applied to the image.

3. What is the purpose of using ANSI C code for image files?

The purpose of using ANSI C code for image files is to create and manipulate digital images. ANSI C is a programming language that allows for precise control and manipulation of decimal values, making it well-suited for handling image data. By using ANSI C code, developers can create complex image processing algorithms and optimize them for efficiency.

4. How do decimal values affect the quality of an image in ANSI C code?

The decimal values used in ANSI C code for image files directly affect the quality of an image. These values determine the color and brightness of each pixel, which ultimately contribute to the overall appearance of the image. By adjusting the decimal values, the contrast, brightness, and color balance of an image can be altered, resulting in different levels of image quality.

5. Are there any limitations to using decimal values in ANSI C code for image files?

Yes, there are some limitations to using decimal values in ANSI C code for image files. One limitation is the range of values that can be represented, as ANSI C typically uses 8-bit integers for storing decimal values. This means that the maximum value for each color component is 255, which may not be enough to accurately represent certain colors. Additionally, manipulating decimal values can be computationally intensive, making it challenging to process large images in real-time.

Similar threads

Replies
2
Views
3K
Back
Top