| | |
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: 34588 | Replies: 14
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi





