Well, hello. I have a problem with reading data from binary files into arrays. For example, let's say that we have d.bin file which contains pairs of strings with max lenght of 32 chars and double values like this: string12.334343 AS34.34 something3 where the string always takes up 32 bytes. Basically, the binary file has a series of types record defined like this: typedef struct{ char name[32]; double value; }record; The question is how would I fread the strings into one array and values into another so that the namearray would contain (string AS something) and the valuearray (12.334343 34.34 …

Member Avatar
Member Avatar
+0 forum 6

Here I am again... The question that I have is this: How do I sort an array of structures by two criteria? One element of the array looks like this: [CODE]struct record{ char name[32]; double value;};[/CODE] The goal would be to sort the array by name and if the name is the same, by value. For example, let's say the array is: A 1 B 13 B 1 B 2 C 3 C 1 The result of sorting should be: A 1 B 1 B 2 B 13 C 1 C 3 My code looks sort of like this: [CODE] …

Member Avatar
Member Avatar
+0 forum 1

Hello. The title pretty much says it all. I would like to know if and how you can print a number (type is double) with the same amount of decimal spaces as the one you entered. If I enter 12.34 I would like the output to be 12.34 and not 12.340000000 Let's say that the program is this: [CODE] #include<stdio.h> double a; main(){ scanf("%lf",&a); printf("%lf\n", a); return 0; } [/CODE]

Member Avatar
Member Avatar
+0 forum 14

Hi once again. As the title implies, the goal of the following code is to create calculator for operations +,-,*,/ and ^. However, the operations are to be executed on values in the files I arbitrarily named a.txt and b.txt. a.txt contains following data: a1 era1 a2 era2 . . . an eran and b.txt: b1 erb1 b2 erb2 . . . bn erbn era and erb are belonging errors in measurement for a and b (in case you are wondering) The result should be in the standard output and look like: a1(operation)b1 resultingerror1(whose value depends on operation, but nevermind) …

Member Avatar
Member Avatar
+0 forum 8

Hi. I have trouble with getting the following program to convert string to float type. What i need to do is this: 12.345e3 = 12345 12e-2=0.12 -12.34=-12.34 -12.34e3=-12340 -12.34e-2=-0.1234 e: = x 10^ I got it to do the basics. However, It doesn't work in case of negative numbers or exponents. While i completely understand it for exponents, i can't say the same for negative numbers. Also, I am pretty sure the code can be optimised. I just don't know how to do it. [CODE]#include <stdio.h> #include <math.h> #define SIZE 1024 int count(char S[SIZE],char c){ { int i=0, count=0 ; …

Member Avatar
Member Avatar
+0 forum 5

Hello to all. I have a problem with replacing a part of a string with another string. The following code does not work. However, if you remove void in front of replace_str, in Code Blocks i am able to run it (WHY???) despite the fact that i still get a warning: "argument 1 of 'puts' makes pointer from integer without a cast" Also, this "program" only replaces the first occurance of s2 in s1 and it should replace all. Plus, i would like to know the correct sintax to print res using printf (the comment in code does not do …

Member Avatar
Member Avatar
+0 forum 6

The End.