Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 12-05-2008, 05:08 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Mar 2007
Posts: 3
Default sorting problem??? help please...


hey guys,

i am doin this program for sorting two-dimnsional aray in ascendin order, and it should accpt N inputs from user... whr N is 7

this is what i have done so far....

void sortLastNames(char name[][N], int N)
{
int count, count1;
char tempname[20];
for(count=0; count<N-1;count++)
{
for(count1=count+1;count1<N;count1++)
{
if(strcmp(name[count], name[count1])>0)
{
strcpy(tempname, name[count]);
strcpy(name[count], name[count1]);
strcpy(name[count1], tempname);
}
}
}
}

now problem is it runs smoothly if u enter input with upto 6 characters, if u enter more than that, it crashes....

please guys reply me back ASAP...

Last edited by jdesai18; 12-05-2008 at 06:39 PM.
jdesai18 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 12-05-2008, 11:43 PM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: sorting problem??? help please...

...;count<N-1;...

If N==7, shouldn't you simply count upto N viz count<N such that it goes from 0 ... 6?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 13-05-2008, 11:10 AM   #3 (permalink)
Apprentice
 
nightcrawler's Avatar
 
Join Date: Sep 2006
Location: Mumbai
Posts: 67
Default Re: sorting problem??? help please...

Quote:
Originally Posted by jdesai18 View Post
hey guys,
void sortLastNames(char name[][N], int N)
This is the reason for it. The above statement means that sortLastNames takes an array of Strings (or 2d array of char). The size of each string is N that is 7. Hence whenever a string greater than 7 is encountered strcmp and strcpy will cause problems.(They have overflow issues as they look for NULL terminating strings '\0').

Fixing this will solve ur problem.
__________________
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.
nightcrawler is offline  
Old 13-05-2008, 02:25 PM   #4 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: sorting problem??? help please...

Quote:
void sortLastNames(char name[][N], int N)
Gives me compile time error with gcc.
__________________
http://www.bash.org/?258908
mehulved is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to disable vista auto sorting files ranjan2001 Software Q&A 1 15-04-2008 12:53 PM
sorting passwords in firefox vicky_l7 Internet & WWW 3 07-09-2007 10:25 PM
Problem With Data Recovary Software Problem Stellar Phoenix njm Software Q&A 1 08-05-2007 12:31 PM
Problem!Problem!Problem Help Me November Cd And December dvd Doesnt Work yyy??? sourav_digit QnA (read only) 3 27-12-2006 02:33 PM
MS Excel worksheet columns not SORTING-PROBLEM MERGED CELLS TVB RAJU Software Q&A 1 29-07-2005 12:50 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2