Click here to Skip to main content
15,914,488 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaloleacc link issues Pin
greekgoddj11-Feb-05 7:02
greekgoddj11-Feb-05 7:02 
GeneralRe: oleacc link issues Pin
greekgoddj13-Feb-05 22:31
greekgoddj13-Feb-05 22:31 
GeneralReading Raw DVD-ROM Pin
Sonix11-Feb-05 6:45
Sonix11-Feb-05 6:45 
GeneralShow dialog window in PreCreateWindow(..) failed :( Pin
bilas11-Feb-05 6:39
bilas11-Feb-05 6:39 
GeneralRe: Show dialog window in PreCreateWindow(..) failed :( Pin
Michael Dunn11-Feb-05 16:37
sitebuilderMichael Dunn11-Feb-05 16:37 
GeneralAccess Database Report Pin
Tom Wright11-Feb-05 6:05
Tom Wright11-Feb-05 6:05 
GeneralRe: Access Database Report Pin
Anonymous11-Feb-05 12:07
Anonymous11-Feb-05 12:07 
GeneralRead file, write to array, find min and max Pin
dr.eu11-Feb-05 5:46
dr.eu11-Feb-05 5:46 
//This program read file *.txt, than 100 float numbers(or int numbers, if they are present)
//write in a float array.Next, finds MIN and MAX element in float array with using pointers,
//write results on the screan and if there is no more numbers, go to end, else repet all again.


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

#define MAXELEMENTS 100 // MAX numbers of elements

//funkcion for max element in float array

float *biggest(float table[],int number)
{
int counter, counter_max;
float aretheysame=0;
for(counter=0; counter < number; counter++)
{
if (*(table+counter) > aretheysame)
{
aretheysame = *(table+counter);
counter_max = counter;
}
}
return(&*(table+counter_max));
}

//finkcion for min element in float array

float *smallest(float table[],int number)
{
int counter, counter_max=0;
float aretheysame=table[0];
for(counter=0; counter < number; counter++)
{
if (*(table+counter) < aretheysame)
{
aretheysame = *(table+counter);
counter_max = counter;
}
}
return(&*(table+counter_max));
}


main(void)
{
FILE *in;
char inter[255];
int num_elements=0;
float element;
static float table[MAXELEMENTS];

float *small,*big;

printf("Adress and value of max and min element in array\n");
printf("Enter file name : ");
gets(inter);
in= fopen(inter,"r");
if(in == NULL)
{
printf("Error. No file with this name\n");
exit(1);
}

while (fscanf(in,"%f",&element) != EOF)
{
table[num_elements] = element;
num_elements++;
}
if (num_elements > 1)
{
big=biggest(table,num_elements);
printf("\nThe adress of max element is %d",&*big);
printf(", with value %f",*big);

small=smallest(table,num_elements);
printf("\nThe adress of min element is %d",&*small);
printf(", with value %f",*small);
}
else
{
;
}
fclose (in);
getchar();
}

And *.txt file:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2000 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
15 14 13 22 55 2 5


The program find min and max from all numbers in file, but not only from 100.
It must be able to do that with long txt files too, and each 100 numbers is work with number (1. work(for first 100 num), 2. work(for secund 100 num),...)

Where I am doing wrong ? Please, help me !

GeneralRe: Read file, write to array, find min and max Pin
David Crow11-Feb-05 6:00
David Crow11-Feb-05 6:00 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 6:05
dr.eu11-Feb-05 6:05 
GeneralRe: Read file, write to array, find min and max Pin
rocky_pulley11-Feb-05 6:09
rocky_pulley11-Feb-05 6:09 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 6:14
dr.eu11-Feb-05 6:14 
GeneralRe: Read file, write to array, find min and max Pin
David Crow11-Feb-05 6:23
David Crow11-Feb-05 6:23 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 6:35
dr.eu11-Feb-05 6:35 
GeneralRe: Read file, write to array, find min and max Pin
David Crow11-Feb-05 6:51
David Crow11-Feb-05 6:51 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 7:08
dr.eu11-Feb-05 7:08 
GeneralRe: Read file, write to array, find min and max Pin
Mattias G11-Feb-05 6:32
Mattias G11-Feb-05 6:32 
GeneralRe: Read file, write to array, find min and max Pin
rocky_pulley11-Feb-05 6:35
rocky_pulley11-Feb-05 6:35 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 6:38
dr.eu11-Feb-05 6:38 
GeneralRe: Read file, write to array, find min and max Pin
rocky_pulley11-Feb-05 6:41
rocky_pulley11-Feb-05 6:41 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 6:49
dr.eu11-Feb-05 6:49 
GeneralRe: Read file, write to array, find min and max Pin
rocky_pulley11-Feb-05 6:52
rocky_pulley11-Feb-05 6:52 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 7:16
dr.eu11-Feb-05 7:16 
GeneralRe: Read file, write to array, find min and max Pin
David Crow11-Feb-05 8:12
David Crow11-Feb-05 8:12 
GeneralRe: Read file, write to array, find min and max Pin
dr.eu11-Feb-05 9:30
dr.eu11-Feb-05 9:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.