I need to write something like this, just plain and simple c.

1. Program starts and prints 5 news titles
2. You select one and it prints news body
3. after viewing you select close and select other one or exit program
4. after that it prints "sort by views" of the news

The main point is to use some of the sorting algorithms. Any suggestions, ideas, pseudocoding since I am newbie?

go to some news web site such as www.cnn.com and select 5 articles. Copy/past a paragraph from each article into your program.

In main() make a menu with the 5 titles and number them a) b) c) d) and e). Then ask for title input. After that create a simple switch statement and which prints the paragraph that is associated with the selected title.

The main point is to use some of the sorting algorithms. Any suggestions, ideas, pseudocoding since I am newbie?

Do a search for Bubble Sort. It's the easiest to understand and for the small amount of data you need it should be more than adequate.

Here is some nasty code, I've translated it from Croatian. Hope it makes
sense.

However, sorting looks pretty nasty and it's written badly. Any suggestions
in changing?
I am stuck with the deadline, only tomorrow is left for me for having fun
with this code.

Thanks in advance.

[LIST=1]
[*]#include <stdlib.h>
[*]#include <stdio.h>

[*]#define MAXLENGTH 20
[*]#define elementtype News
[*]#define N 9                //number of news

[*]typedef struct {
[*]       int ID;
[*]       char name[60];
[*]       char text[500];      //structure
[*]       int read;
[*]       } News;


[*]typedef struct {
[*]int last;
[*]elementtype elements[MAXLENGTH];
[*]} LIST;

[*]void bubblesort(int *array){
[*]    int i,j,k;
[*]    for (i=0; i<N; i++){
[*]        for (j=N-1; j>i; j--){
[*]            if (array[j-1]<array[j]){     //Bubble sort
[*]              k=array[j];
[*]              array[j]=array[j-1];
[*]              array[j-1]=k;
[*]              }
[*]        }
[*]    }
[*]}


[*]int main()
[*]{
[*]    int n;                  // how many times we will allow analysis before 
[*]reading
[*]    int decision;

[*]    News new1 = {1,"heading 1.", "body 1"};

[*]    News new2 = {2,"heading 2.", "body 2"};

[*]    News new3 = {3,"Heading 3.", "body 3"};

[*]    News new4 = {4,"heading 4.", "body 4"};

[*]    News new5 = {5,"heading 5.", "body 5"};

[*]    News new6 = {6,"heading 6.", "body 6"};

[*]    News new7 = {7,"Heading 7.", "body 7"};

[*]    News new8 = {8,"Heading 8.", "body 8"};

[*]    News new9 = {9,"heading 9.", "body 9"};

[*]    printf("\t\t\tWelcome to the news sorting!\n\n\n\n");

[*]    for (n=0;n<15;n++){
[*]       printf("%d-->  %s\n", new1.ID, new1.name,0);
[*]       printf("%d-->  %s\n", new2.ID, new2.name,0);
[*]       printf("%d-->  %s\n", new3.ID, new3.name,0);
[*]       printf("%d-->  %s\n", new4.ID, new4.name,0);
[*]       printf("%d-->  %s\n", new5.ID, new5.name,0);
[*]       printf("%d-->  %s\n", new6.ID, new6.name,0);
[*]       printf("%d-->  %s\n", new7.ID, new7.name,0);
[*]       printf("%d-->  %s\n", new8.ID, new8.name,0);
[*]       printf("%d-->  %s\n\n", new9.ID, new9.name,0);
[*]       printf("Enter number + ENTER for reading: ");
[*]       scanf("%d",&decision);
[*]        if (decision==1){
[*]            printf("---------------------------------------\n%s\n", 
[*]new1.text);
[*]            new1.read++;}
[*]        if (decision==2){
[*]            printf("---------------------------------------\n%s\n", 
[*]new2.text);
[*]            new2.read++;}
[*]        if (decision==3){
[*]            printf("---------------------------------------\n%s\n", 
[*]new3.text);
[*]            new3.read++;}
[*]        if (decision==4){
[*]            printf("---------------------------------------\n%s\n", 
[*]new4.text);
[*]            new4.read++;}
[*]        if (decision==5){
[*]            printf("---------------------------------------\n%s\n", 
[*]new5.text);
[*]            new5.read++;}
[*]        if (decision==6){
[*]            printf("---------------------------------------\n%s\n", 
[*]new6.text);
[*]            new6.read++;}
[*]        if (decision==7){
[*]            printf("---------------------------------------\n%s\n", 
[*]new7.text);
[*]            new7.read++;}
[*]        if (decision==8){
[*]            printf("---------------------------------------\n%s\n", 
[*]new8.text);
[*]            new8.read++;}
[*]        if (decision==9){
[*]            printf("---------------------------------------\n%s\n", 
[*]new9.text);
[*]            new9.read++;}

[*]            system("pause");
[*]            system("cls");              }


[*]    int array[N]={new1.read, new2.read, new3.read, new4.read, new5.read, 
[*]new6.read, new7.read, new8.read, new8.read};


[*]    bubblesort(array); // call bubblesort


[*]    //Most read news-------------------------------
[*]    if (new1.read==array[0]){
[*]         printf("Most read news is:\t%s", new1.name);}
[*]    if (new2.read==array[0]){
[*]         printf("Most read news is:\t%s", new2.name);}
[*]    if (new3.read==array[0]){
[*]         printf("Most read news is:\t%s", new3.name);}
[*]    if (new4.read==array[0]){
[*]         printf("Most read news is:\t%s", new4.name);}
[*]    if (new5.read==array[0]){
[*]         printf("Most read news is:\t%s", new5.name);}
[*]    if (new6.read==array[0]){
[*]         printf("Most read news is:\t%s", new5.name);}
[*]    if (new7.read==array[0]){
[*]         printf("Most read news is:\t%s", new7.name);}
[*]    if (new8.read==array[0]){
[*]         printf("Most read news is:\t%s", new8.name);}
[*]    if (new9.read==array[0]){
[*]         printf("Most read news is:\t%s", new9.name);}
[*]    //-------------------------------------------------

[*]    printf("\n");

[*]    //2. Second most read news-------------------------------
[*]    if (new1.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new1.name);}
[*]    if (new2.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new2.name);}
[*]    if (new3.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new3.name);}
[*]    if (new4.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new4.name);}
[*]    if (new5.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new5.name);}
[*]    if (new6.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new6.name);}
[*]    if (new7.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new7.name);}
[*]    if (new8.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new8.name);}
[*]    if (new9.read==array[1]){
[*]         printf("2. Most read news is:\t%s", new9.name);}
[*]    //-------------------------------------------------

[*]    printf("\n");

[*]    //3. most read news-------------------------------
[*]    if (new1.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new1.name);}
[*]    if (new2.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new2.name);}
[*]    if (new3.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new3.name);}
[*]    if (new4.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new4.name);}
[*]    if (new5.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new5.name);}
[*]    if (new6.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new6.name);}
[*]    if (new7.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new7.name);}
[*]    if (new8.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new8.name);}
[*]    if (new9.read==array[2]){
[*]         printf("3. Most read news is:\t%s", new9.name);}
[*]    //------------------------------------------------- 

[*]    printf("\n\nDiffernce between the TOP news and one in the middle is: 
[*]%d - %d = %d", array[0], array[4], array[0] - array[4]);


[*]    printf("\n\n");
[*]    system("pause");
[*]    return 0;
[*]}
[/LIST]

Here is some nasty code, I've translated it from Croatian. Hope it makes
sense.

However, sorting looks pretty nasty and it's written badly. Any suggestions
in changing?
I am stuck with the deadline, only tomorrow is left for me for having fun
with this code.

First of all, why aren't you using an array for news1 to news9? Wouldn't that make your program much shorter and easier to follow?

Why do you claim sorting looks pretty nasty and it's written badly? What is it you don't like about the code? Assuming it works (you never said it didn't) all I see is an inconsistent use of spaces throughout the program (usually in FOR and IF statements) making it hard to read. Add them around operators like for (i = 0; i < N; i++){ if (array[j-1] < array[j]){ all over the program.

Why are you using the LIST tag in your CODE tags?

This article has been dead for over six months. Start a new discussion instead.