how can you make program using a linked list that displays your outputs in ascending alphabetical order?

we are only allowed to use:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

TIA

Recommended Answers

All 10 Replies

how can you make program using a linked list that displays your outputs in ascending alphabetical order?

With a computer, keyboard, monitor, mouse (optional), an OS and some software. You'll probably need your eyes, brains, arm, hand etc too.

In other words: Try something yourself first and come back with specific questions.

In the meantime, reading this will probably help you.

aaaaaaaah so that's how it is. I was thinking more of like looking at it, concentrate, and it'll answer itself. You know, like telekinesis or something like that.

I'm asking because I'm confused when using strings.. its not like int or float that you just compare it with < or > etc. I tried to use strcmp() but I'm not sure if this will work. I just need someone to point me in the right direction, and not some sarcasm shit!
THx btw..

aaaaaaaah so that's how it is. I was thinking more of like looking at it, concentrate, and it'll answer itself. You know, like telekinesis or something like that.

Telekinesis seldom works for me

I just need someone to point me in the right direction, and not some sarcasm shit!
THx btw..

How about I help you in the right direction and still stay a sarcastic kind of guy?

Here's a link on strcmp

And here's some example-code that uses strcmp()

#include <string.h>
#include <stdio.h>


int main()
{
    char string1[] = "something";
    char string2[] = "something else";
    char string3[] = "something";
    if (!strcmp(string1, string2))
        printf("String 1 and 2 are the same!\n");
    else
        printf("String 1 and 2 are not the same...\n");
    
    if (!strcmp(string2, string3))
        printf("String 2 and 3 are the same!\n");
    else
        printf("String 2 and 3 are not the same...\n");
    
    if (!strcmp(string1, string3))
        printf("String 1 and 3 are the same!\n");
    else
        printf("String 1 and 3 are not the same...\n");

    getchar();
    return 0;
}

hey this is kinda fun.

i already know the basics of strcmp() .
so, based on your answer, it can be done using strcmp() right?
how will it suppose to know that Bryant, Kobe comes before Jordan, Michael, and
James ,LeBron is in between the 2 of them?
it only checks if they are similar right? or is there more to it?

Yes, return value will be negative or positive or zero. Relearn the basics of strcmp()

THx

according to the link niek_e gave

"Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite."

in the underlined part, by greater value does it mean that A has greater value than B?

>in the underlined part, by greater value does it mean that A has greater value than B?
strcmp compares each character in order and returns the result of the first two characters that don't match. It's equivalent to this implementation:

int jcmp ( const char *a, const char *b )
{
  while ( *a == *b && *a != '\0' ) {
    ++a;
    ++b;
  }

  if ( *a < *b )
    return -1;
  else if ( *a > *b )
    return +1;

  return 0;
}

The final comparison is a direct comparison of the underlying integer value for the two characters. So "a" will be greater than "A" under ASCII because 'a' has a value of 97 and 'A' a value of 65.

This can sometimes be confusing if you're expecting comparisons for a natural ordering rather than lexicographical ordering by the underlying character set.

Ok I get it. thanks for that..
I didn't know that it has something to do with ASCII.
so 'B'(66) is greater than 'A'. am I right?

so for a telephone directory will it be appropriate to use strcmpi() or stricmp() ?
so 'a' and 'A' will result in them being equal.

>so for a telephone directory will it be appropriate to use strcmpi() or stricmp() ?
That's a reasonable requirement.

thanks. I have a related question. do I have to start a new thread for this?

can someone help me? Still confused in linked lists.
there's something wrong when I input a record for the 2nd time.
But sometimes it works and then when I display all records It doesn't display correctly.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node *nd;

struct node{
		  int next;
		  char telnum[15];
                  char fname[30];
                  char lname[30];
		  char address[70];
	}NODE;

menu();
Insert(nd *head);
Display(nd *head);

main()
{
	int m;
	char ans;
        nd head=NULL;

	do{
		clrscr();
		m=menu();
		switch(m)
        	{
		case 1: Insert(&head);
		break;
		case 2: printf("under construction");
		break;
		case 3: printf("under construction");
		break;
		case 4: Display(&head);
		break;
		case 5:
		break;
		default: {printf("Enter a number from the menu.");
			 getch();}
		break;
		}
	}while(m!=5);
}

menu()
{
	int menu;
	printf("1. Data Entry\n2. Search and Edit\n3. Search and Delete\n");
	printf("4. Display all records\n5. Exit\nchoice: ");
	scanf("%d" ,&menu);
	return menu;
}

Insert(nd *head)
{  int x=14,y=1;
	nd temp, h=*head;
	char tel[15], ln[20], fn[20], ad[50];
	clrscr();

	printf("Last name: \n");
	printf("First name: \n");
	printf("Tel. Number: \n");
	printf("Address: ");
	gotoxy(x,y++); scanf("%s", &ln);
	gotoxy(x,y++); scanf("%s", &fn);
	gotoxy(x,y++); scanf("%s", &tel);
	gotoxy(x,y++); scanf("%s", &ad);

	if (h==NULL){
	    h=malloc(sizeof(NODE));
		 strcpy(h->lname, ln);
		 strcpy(h->fname, fn);
	         strcpy(h->telnum, tel);
		 strcpy(h->address, ad);
	    h->next=NULL;
	    *head=h;
	  }

	else {
	     temp=malloc(sizeof(NODE));
	     strcpy(temp->telnum, tel);
	     temp->next=h;
	     h=temp;
	     *head=h;
	   }

	free(temp);
}

Display(nd *head)
{
	nd p=*head;
	clrscr();

	while(p!=NULL){
		puts(p->lname);
		puts(p->fname);
		puts(p->telnum);
		puts(p->address);
		p=p->next;
		}

	getch();
}
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.