I had this same problem about two days ago. qsort is what you need. This program works:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float data[10];
float a, b;
int compare(const void *, const void *);
int compare(const void *a, const void *b)
{
float x, y;
x =...
I have another question. This one is about sorting numbers in an array. I want to write a program that will print out the largest number in an array. I have seen lots of threads about qsort but I'm confused as to how to use it. I have tried writing something like this.
#include <stdio.h>...
I am writing a program that reads (x,y,z) coordinates from a text file and then manipulates them. I need to store the (x,y,z) coordinates in an array. The problem is that there is a different number of points in each file, so I need to use dynamic memory allocation. I have tried using a...
I had tried to write something like this, but I keep getting segmentation faults. This program might be way off of what I want to do, but I am a beginner.
#include <stdio.h>
main()
{
char name[100];
char cont[100];
FILE *thefile;
(void)printf("What file? ");
(void)fgets(name...
I am a beginner programmer and have a rudimentary knowledge of C and no knowledge of the other languages. I need to write a program that will first ask the user to type in the name of the file that he wants to open, then opens that file and displays the contents on the screen. It will be the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.