| | |
sorting an array of string
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Just wanted to show how it works inside. It would sure help in understanding what goes on.
btw,what the use if all use something without knowing how it works
btw,what the use if all use something without knowing how it works
•
•
Join Date: May 2004
Posts: 15
Reputation:
Solved Threads: 0
hi miss matika. strncmp() is the easiet way for comparing strings and it helps in arranging.
for example if you want to arrange accoring to the first letter
strncmp(st1,st2,1) // 1 is the number of letters you are going arrange according to it.
1- the function returns 0 if the letters are the same
2- the function returns -1 if the first letter of st1 smaller than st2
3- the function returns 1 if the first letter of st2 smaller than st1
The question is : Is there is a function which switch the places of two strings with each other.
you can also use this function... balas(); " It is very usefull trust me "
but u must include "radi.h"
thnx
bye :cheesy:
for example if you want to arrange accoring to the first letter
strncmp(st1,st2,1) // 1 is the number of letters you are going arrange according to it.
1- the function returns 0 if the letters are the same
2- the function returns -1 if the first letter of st1 smaller than st2
3- the function returns 1 if the first letter of st2 smaller than st1
The question is : Is there is a function which switch the places of two strings with each other.
you can also use this function... balas(); " It is very usefull trust me "
but u must include "radi.h"
thnx
bye :cheesy:
The answer is quite simple:
Just use "<"or">" operators in an "if" instruction like in a normal sorting method for numbers. Be careful though:
if you have:
s1[]="abcdef",s2[]="afsdg"; and you write
if (s1>s2) printf("1");
else printf("2"); it will write 2 as in s2 larger than s1 so s1 has to be first: abcdef, afsdg
Hope it helps! :cheesy:
Just use "<"or">" operators in an "if" instruction like in a normal sorting method for numbers. Be careful though:
if you have:
s1[]="abcdef",s2[]="afsdg"; and you write
if (s1>s2) printf("1");
else printf("2"); it will write 2 as in s2 larger than s1 so s1 has to be first: abcdef, afsdg
Hope it helps! :cheesy:
![]() |
Similar Threads
- Sorting an Array of String (Visual Basic 4 / 5 / 6)
- Problem of sorting words of each string using pointers (C++)
- bubble sorting in an array (C)
- Conver int Array into a String (Java)
- Array to String (PHP)
Other Threads in the C Forum
- Previous Thread: Please help with algorithm
- Next Thread: New Type
Views: 34576 | Replies: 14
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm command copyimagefile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux hacking histogram homework ide include incrementoperators input intmain() iso kernel keyboard kilometer lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf openwebfoundation overwrite pause pdf pointer pointers posix process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming spoonfeeding standard strchr string student system testing threads turboc unix urboc user whythiscodecausesegmentationfault windowsapi





