Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,170 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,905 people online right now. Registration is fast and FREE... Join Now!




pointers in a function error

 
Reply to this topicStart new topic

pointers in a function error

cowface
7 Dec, 2007 - 09:49 AM
Post #1

New D.I.C Head
*

Joined: 6 Dec, 2007
Posts: 1


My Contributions
It seems like a simple syntax error but I cant seem to figure out why i am getting this error,
error C2664: 'swap' : cannot convert parameter 1 from 'char **__w64 ' to 'char *'
the program is suppose to take these given names (and it has to be in this order) and sort them in alphabetical order. I'm pretty sure my lodgic is correct, but my deadline for this assighnment is approaching and i wanted to make sure. Thanks for the help!

CODE

#include "stdio.h"
#include "math.h"
#include "string.h"

void main ()
{

char name[5][10] = {"Bob", "June", "David", "Lenny", "Daisy"};
char * a;
char * b;
int x, p;
void swap (char*,char*);
a=(*name);
for (a=(*name);a<(*name+4);a=(*name+1))
{
    for (b=(*name+1);b<(*name+4);b=(*name+1))
    {
    x=strcmp(a,b);
        if(x>0)
        {
        swap(&a,&b);
        }
    }
}
for (p=0;p<5;p++)
{
printf("%s \n",name[p][10]);

}
}
void swap (char *a, char *b)
{
char temp;
temp=*a;
*a=*b;
*b=temp;
}

User is offlineProfile CardPM
+Quote Post

Bench
RE: Pointers In A Function Error
7 Dec, 2007 - 10:23 AM
Post #2

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 617



Thanked: 14 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
CODE

                swap(&a,&b);

a and b are already type char*, so lose the & from the front, and you should be good to go.


Also, look carefully at your loops, specifically the modifier expression - The loops will just run forever
CODE

for (a=(*name);a<(*name+4);a=(*name+1))
{
    for (b=(*name+1);b<(*name+4);b=(*name+1))
    {


This post has been edited by Bench: 7 Dec, 2007 - 10:23 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:32AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month