The following error appears: 'strcmp' : cannot convert parameter 1
from 'char' to 'const char *'. I've already tried using single
quotations. the header file
only contains the struct contents. The whole program is part of an
example found in my course work. Does strcmp only compare two sets of
strings or can it be used to determine the end of the string as well?
#include<iostre am>
#include<iomani p>
#include<cstdli b>
#include<cstrin g>
#include "program2v. h"
using namespace std;
int main()
{
crecord *string1, *string2, t_str;
*string1 = t_str;
/// the error while( strcmp(*string1->customername , "\0"))
{
*string2 = *string1 + 1;
while( strcmp(*string2->customername , '\0'))
{
if(strcmp( *string1->customername , *string2->customername ) > 0 )
{
t_str = *string1;
*string1 = *string2;
*string2 = t_str;
}
string2++;
}
string1++;
}
return 0;
} 6 12494
"muser" <ch**********@h otmail.com> wrote in message
news:f9******** *************** ***@posting.goo gle.com... The following error appears: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'. I've already tried using single quotations. the header file only contains the struct contents. The whole program is part of an example found in my course work. Does strcmp only compare two sets of strings or can it be used to determine the end of the string as well? #include<iostre am> #include<iomani p> #include<cstdli b> #include<cstrin g> #include "program2v. h"
using namespace std;
int main() {
crecord *string1, *string2, t_str;
*string1 = t_str;
Uhm, 'string1' is a wild pointer, and you are just mighty lucky you did
not blow up your program right here. Make sure 'string1' and 'string2' point
to valid objects before working with them. /// the error while( strcmp(*string1->customername , "\0")) { *string2 = *string1 + 1;
Same here. You are dereferencing pointer with an unknown value ...
while( strcmp(*string2->customername , '\0'))
What are you trying to do? 'strcmp', as the name suggests, takes two
strings (ie. char-arrays) and compares them. It looks like you want to
compare plain chars? If so, do this:
while (*string2->customername != '\0')
{ if(strcmp( *string1->customername , *string2->customername ) > 0 )
What is the type of crecord::custom ername? char* ?
{ t_str = *string1; *string1 = *string2; *string2 = t_str;
} string2++; } string1++; }
return 0; }
No offense, but I suggest you get a good tutorial online or a book
before coding more. From that snippet above, you seem to be confused by
pointers and objects and string manipulation.
hth
--
jb
(replace y with x if you want to reply by e-mail)
"muser" <ch**********@h otmail.com> wrote in message
news:f9******** *************** ***@posting.goo gle.com... /// the error while( strcmp(*string1->customername , "\0")) { *string2 = *string1 + 1; while( strcmp(*string2->customername , '\0')) { if(strcmp( *string1->customername , *string2->customername ) > 0 ) {
Where is your structure defined ? Specifically, I need to know what data
type the "customerna me" field is. Also, the '\0' argument is not a valid
parameter type to strcmp(). What are you trying to accomplish ? If
customername is a pointer to a character string and you want to test if the
string is empty, you can just do something like:
while (*(string2->customername ) == '\0')
muser wrote: The following error appears: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'. I've already tried using single quotations. the header file only contains the struct contents. The whole program is part of an example found in my course work. Does strcmp only compare two sets of strings or can it be used to determine the end of the string as well?
#include<iostre am> #include<iomani p> #include<cstdli b> #include<cstrin g> #include "program2v. h"
using namespace std;
int main() {
crecord *string1, *string2, t_str;
What is crecord?
*string1 = t_str;
You deferenced a pointer without having set it to any value. Where do
you think string1 points? /// the error while( strcmp(*string1->customername , "\0"))
What is customername? What type? Are you sure that dereference does what
you think it does?
In the future, post *complete* minimal programs. We don't have your
header file.
Also, explain what the basic concept of the program is. Your code had no
comments at all.
Brian Rodenborn
Default User <fi********@com pany.com> wrote in message news:<3F******* ********@compan y.com>... muser wrote: The following error appears: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'. I've already tried using single quotations. the header file only contains the struct contents. The whole program is part of an example found in my course work. Does strcmp only compare two sets of strings or can it be used to determine the end of the string as well?
#include<iostre am> #include<iomani p> #include<cstdli b> #include<cstrin g> #include "program2v. h"
using namespace std;
int main() {
crecord *string1, *string2, t_str;
What is crecord?
*string1 = t_str;
You deferenced a pointer without having set it to any value. Where do you think string1 points?
/// the error while( strcmp(*string1->customername , "\0"))
What is customername? What type? Are you sure that dereference does what you think it does?
In the future, post *complete* minimal programs. We don't have your header file.
Also, explain what the basic concept of the program is. Your code had no comments at all.
Brian Rodenborn
my code again in a simpler reworked format. strcmp produces the
following error:
C:\Program Files\Microsoft Visual
Studio\MyProjec ts\Valid\progra m2\program2v.cp p(52) : error C2664:
'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
if string1 and string 2 have to be const chars, how can i dereference
them later in the function?
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
struct crecord {
long customercode[5];
char customername[21];
char customeraddress[61];
double customerbalance ;
double creditlimit;
};
crecord Newcrecord;
struct irrecord {
long customercode[5];
long partnum[5];
long issue_rec;
};
irrecord Newirrecord;
struct drecord {
long customercode[5];
};
drecord Newdrecord;
void sort( char* record )
{
char t_str;
char characterstring[5];
char* string1;
char* string2;
strncpy(charact erstring, &record[2], 5);
characterstring[5] = '\0';
while(*(string1 ) != '\0')
{
*string2 = *string1;
*string2++;
while( *(string2) != '\0')
{
if(strcmp( *string1, *string2 ) > 0)
{
t_str = *string1;
*string1 = *string2;
*string2 = t_str;
}
string2++;
}
string1++;
}
return;
}
int main()
{
const char outfile[] = "A:\\514650VD.D AT";
ofstream validdata;
char temp2[256];
return 0;
}
muser wrote: my code again in a simpler reworked format. strcmp produces the following error: C:\Program Files\Microsoft Visual Studio\MyProjec ts\Valid\progra m2\program2v.cp p(52) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
if string1 and string 2 have to be const chars, how can i dereference them later in the function?
The have to be POINTERS to const char. You are passing in a single char.
char* string1; char* string2;
if(strcmp( *string1, *string2 ) > 0)
You dereference the two char pointers, which yields a char, which
generates a diagnostic. Hurray, the system works! Go with this:
if(strcmp( string1, string2 ) > 0)
Brian Rodenborn ch**********@ho tmail.com (muser) writes: The following error appears: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'. I've already tried using single quotations. the header file only contains the struct contents.
... which would be necessary to understand what's going on here.
Please post the minimal *complete*, *compilable* example showing your
problem.
The whole program is part of an example found in my course work. Does strcmp only compare two sets of strings or can it be used to determine the end of the string as well? #include<iostre am> #include<iomani p> #include<cstdli b> #include<cstrin g> #include "program2v. h"
using namespace std;
int main() {
crecord *string1, *string2, t_str;
*string1 = t_str;
Here you're assigning to a pointer for which no memory has been allocated.
/// the error while( strcmp(*string1->customername , "\0"))
It seems that crecord::custom ername is a char - strcmp is for comparing
char*. If you really want to compare two chars (which I doubt),
just use operator==, e.g.
if (*string1->customername == '\0')
Note the single quote.
I'm also wondering what you want to achieve with dereferencing
string1->customername - but without the header file, it's impossible to guess.
HTH & kind regards
frank
--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jl_post |
last post by:
Hi,
I recently wrote two benchmark programs that compared if two strings
were equal: one was a C program that used C char arrays with strcmp(),
and the other was a C++ program that used std::strings with
operator==().
In both programs, the first string consisted of one million
characters (all the letter 'a'). The second string was always one
character longer than the first string (with the letter 'a' for all the
|
by: Allan Bruce |
last post by:
Hi there,
I am reading a file into a char array, and I want to find if a string exists
in a given line.
I cant use strcmp since the line ends with '\n' and not '\0'. Is there a
similar function that will do this, or will I have to write my own?
Thanks
Allan
|
by: Eirik |
last post by:
Shouldn't this code work? If not, why shouldn't it?
#include <stdio.h>
int main(void)
{
char yesno;
char *yes = "yes";
|
by: Steven |
last post by:
Hello,
I have a question about strcmp(). I have four words, who need to be
compared if it were two strings. I tried adding the comparison values
like '(strcmp(w1, w2) + strcmp(w3, w4))', where w1 and w2 make up the
first string and, w3 and w4 make up the second string. I do not want
to allocate memory, then put the words together to create a string
only to facilitate strcmp() comparison.
My question; Does anyone know how to get the...
|
by: Sameer |
last post by:
Hi friends,
I am beginner in C++. I am using g++ compiler. below is my code
which gives error as " invlid conversion from 'char' to 'const char*'
..Plz help me with this.
#include <iostream.h>
#include <string.h>
int low_range(char symbol) ;
int main(int argc, char **argv)
| |
by: Chuck Faranda |
last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem
is getting serial data back from my device. My get commands have to be sent
twice for the PIC to respond properly with the needed data. Any ideas?
Here's the code in question, see any reason why a command would not trigger
the 'kbhit' the first time a serial command is sent?: Thanks!
Chuck
****************************************************
while(1) //...
|
by: noobcprogrammer |
last post by:
#include "IndexADT.h"
int IndexInit(IndexADT* word)
{
word->head = NULL;
word->wordCount = 0;
return 1;
}
int IndexCreate(IndexADT* wordList,char* argv)
|
by: fishpond |
last post by:
One way I've seen strcmp(char *s1, char *s2) implemented is: return
immediately if s1==s2 (equality of pointers); otherwise do the usual
thing of searching through the memory at s1 and s2.
Of course the reason for doing this is to save time in case equal
pointers are passed to strcmp. But it seems to me that this could create
an inconsistency in the degenerate case when s1 points to memory that is
not null-terminated, i.e. by some freak...
|
by: thungmail |
last post by:
There is partial code in C
typedef struct message {
int messageId;
char *messageText;
struct message *next;
}message;
.....
.....
.....
/* Get a node before a node */
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |