4 Replies - 2720 Views - Last Post: 01 November 2001 - 09:19 AM Rate Topic: -----

#1 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4496
  • View blog
  • Posts: 28,404
  • Joined: 21-March 01

linked lists, arrays, and bubble sorts

Posted 30 October 2001 - 10:13 AM

im trying to assign the info in the linked list, to an array, so that i can peform a bubble sort on the code. but the username(funcuser variable) wont print out in the do while loop. i would think this code is correct. here the functions code, and the struct declaration. thanx in advance.
struct input
{
char user[30];
char id[20];
int grades1;
int grades2;
int grades3;
int grades4;
int grades5;
int avg;
input *next;
};

int j,i=1,funcavg[50]; char funcuser[50][36]; current=head; cout << " UsernameID numberAverage " << " ------------------------ "; do { strcpy(funcuser[i]," "); strcat(funcuser[i], current->user); funcavg[i]=current->avg; current=current->next; i++; } while(current!=NULL); for(j=1;j<i;j++) {cout << setw(1) << funcuser[j][36] << setw(12) << funcavg[j] << " ";}



Is This A Good Question/Topic? 0
  • +

Replies To: linked lists, arrays, and bubble sorts

#2 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: linked lists, arrays, and bubble sorts

Posted 31 October 2001 - 08:36 AM

funcuser is a two dimensional array...you should have a subscript in both the strcpy and the strcat statements.
Was This Post Helpful? 0
  • +
  • -

#3 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4496
  • View blog
  • Posts: 28,404
  • Joined: 21-March 01

Re: linked lists, arrays, and bubble sorts

Posted 31 October 2001 - 09:18 AM

yea, ive done that, and i get these errors.
--------------------Configuration: gradebook (program 4) - Win32 Debug--------------------
Compiling...
gradebook (program 4).cpp
D:Josh RiveraAdvanced Computer Scienceprogram 4gradebook (program 4).cpp(516) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:Josh RiveraAdvanced Computer Scienceprogram 4gradebook (program 4).cpp(517) : error C2664: 'strcat' : cannot convert parameter 1 from 'char' to 'char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

gradebook (program 4).exe - 2 error(s), 0 warning(s)


Was This Post Helpful? 0
  • +
  • -

#4 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: linked lists, arrays, and bubble sorts

Posted 31 October 2001 - 01:21 PM

Ah yes, I forgot that part. The str functions all take dynamic character arrays as their arguments. All you need to do is put an address-of operator in front of the character array names:
strcpy(&funcuser[i], " ");


edit:took out smiley

(Edited by supersloth at 10:16 am on Nov. 1, 2001)

Was This Post Helpful? 0
  • +
  • -

#5 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4496
  • View blog
  • Posts: 28,404
  • Joined: 21-March 01

Re: linked lists, arrays, and bubble sorts

Posted 01 November 2001 - 09:19 AM

ok, that worked without errors, but when it prints out, i get nothing from those variables, but at least im not getting those weird ass symbols....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1