473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

string compare fucntion(Emergency)

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5.        char  lname[40], name[40][40];
  6.        int   i, j, k;
  7.        printf("Enter the number of names:  ");
  8.        scanf("%d",&k);
  9.        for(i=0; i<k; i++)
  10.        {
  11.               printf("\nEnter the name%d:",i+1);
  12.               scanf("%s",name[i]);
  13.        }
  14.        for(i=0; i<k-1; i++)//for moving through the rows,movement will be until the row which is before the last row
  15.        for(j = i+1; j<k; j++)
  16.        if(strcmp(name[i], name[j])>0)//this if compare string  condition. it must be true it means one of these two names must be bigger than the second to enter our inner loop
  17.        {
  18.               strcpy(lname, name[i]);
  19.               strcpy(name[i], name[j]);
  20.               strcpy(name[j], lname);
  21.        }
  22.        printf("\nNames In Alphabetic Sorted Order:\n");
  23.        for (i =0; i<k; i++)
  24.        printf("%s\n",name[i]);
  25.        return 0;
  26. }
we have such program know we have to write a function to do the compare and copy and use it insted of strcpy and strcmp .function use pointer arithmetic to go forward in the string.
body of function must be a for loop without any body.

i try several things but i can't find the way .
Dec 1 '06 #1
1 1467
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5. char lname[40], name[40][40];
  6. int i, j, k;
  7. printf("Enter the number of names: ");
  8. scanf("%d",&k);
  9. for(i=0; i<k; i++)
  10. {
  11. printf("\nEnter the name%d:",i+1);
  12. scanf("%s",name[i]);
  13. }
  14. for(i=0; i<k-1; i++)//for moving through the rows,movement will be until the row which is before the last row
  15. for(j = i+1; j<k; j++)
  16. if(strcmp(name[i], name[j])>0)//this if compare string condition. it must be true it means one of these two names must be bigger than the second to enter our inner loop
  17. {
  18. strcpy(lname, name[i]);
  19. strcpy(name[i], name[j]);
  20. strcpy(name[j], lname);
  21. }
  22. printf("\nNames In Alphabetic Sorted Order:\n");
  23. for (i =0; i<k; i++)
  24. printf("%s\n",name[i]);
  25. return 0;
  26. }
we have such program know we have to write a function to do the compare and copy and use it insted of strcpy and strcmp .function use pointer arithmetic to go forward in the string.
body of function must be a for loop without any body.

i try several things but i can't find the way .
Have a go at it and let's see.
Hint: For compare, compare the strings character by character
Dec 1 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Alex Martelli | last post by:
All my mailboxes have been filling up with files of about 130k to 150k, no doubt copies of some immensely popular virus. So, I've no doubt lost lots of real mail because of "mailbox full"...
1
by: Paul | last post by:
Hi, I'm try to pass a string to a variable in SQL Server, and have that string used with "IN" clause to return multiple results. This doesn't work. Can anybody help? DECLARE @in_codes...
4
by: in da club | last post by:
i get error '80040e14' from this codes.. sqlbul="select * from buyers where sesid="&session.SessionID set rsbul=baglantim.execute(sqlbul) if rsbul.eof then
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
2
by: Shawn Zheng | last post by:
Does any one can to me faverite? How to associated an account with a trusted SQL connection I created a login account in SQL 2000 server, can add the user into a database that I work on. but I got...
2
by: Shawn Zheng | last post by:
I found the problem is the conneciton string seems did not take effect. Does any one met this problem? I dragged connection string from Server exploer in Visual Studio into web form. the form in...
14
by: c676228 | last post by:
Hi everyone, Our site is down, because of our hosting company applied sql server 2000 sp4 on windows 2000 server. right after it applied the service pack, our sql server database is down and...
5
by: ahin | last post by:
my probgram doesn't show the total mark and the grade1 can any one solve the problem? this is easy thing but i vahe only 15 min to solve it #include<iostream> #include<string> using...
0
by: Juan Alvarez | last post by:
Hi everyone, this is an emergency =S I have a Word document that use a Template with Custom Properties. The template has one Field that once i fill it, it calls another applicaton an fill the rest...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.