guys Im a newbie here I really need your help for our project...pls help me..heres the problem..Write a C program that add a names into a file then read the names in a file and sort it alphabetically..(FILEPOINTER).

Recommended Answers

All 2 Replies

And how would you do it? You will need proto make an effort here, then you will get help from others.
Helping you with your project or assignment does not include doing them for you. Is that not?

As 2teez says, the policy at Daniweb is that you must give demonstrate that you have made a good faith effort to solve your problem yourself, and that respondents are expected to only provide support and assistance, not provide full solutions. Show us what you have tried so far, or at least explain what you need help with, and we will do what we can to help, but we cannot and will not simply write your program for you.

I know that this is probably not what you meant, but it is what it came across as. If nothing else, you need to be more deliberate and specific with your questions in the future.

Having said that, I noticed one thing about the assignment as decribed: the order in which you are to do things seems off. Are you certain that you are to write the unsorted names to the files, then read them in, and finally sort them after they have been written? It seems to make more sense to have the names sorted before writing them out.

Have you covered how to read and write files in class already? The general approach is something like this:

#include <stdio.h>

#define BUFSIZE 1023

int main()
{
    char buffer[BUFSIZE + 1];
    FILE in_file, out_file;

    in_file = fopen("my_file.txt", "r");  /* open file to read it */ 
    fgets(buffer, BUFSIZE, in_file); /* read in one line */
    fclose(in_file);

    my_sort(buffer);    / sort the string elements */

    out_file = fopen("out_file.txt", "w"); /* open file to write to it */
    fputs(buffer, BUFSIZE, out_file);  /* write the same string back out */
    fclose(out_file);

    return 0;
}    

This is just a quick sketch of how it works; your program would be quite different.

Also, do you have to write the sorting function yourself, or can you use the standard qsort() library function? I assume the former, but if you can use the existing sorting function, it would save a lot of trouble.

Can you post the exact problem statement, please, along with any code you have written so far?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.