|
|
the diff b/w long pointer to string and pointer to string and where each one is used
|
|
|
|
|
what is your question exactly ?
anyway for what i understand, long pointer specifies that the pointer is as wide as a long
|
|
|
|
|
hari prasad sathpadi wrote: the diff b/w long pointer to string and pointer to string and where each one is used
There is no difference on 32 (or 64) bit Windows. It is a legacy from 16-bit days.
|
|
|
|
|
In modern Windows, none at all. LPSTR and PSTR are fully interchangeable.
On 16-bit Windows (and DOS), you had two sorts of pointer, near and far . A near pointer was 16 bits and could only reference data in the same segment as currently set, while a far pointer was 32 bits and could reference data in any segment. Data in a DLL would never be in your program's segment, so you'd need a far pointer to address it.
Segmented addressing was a really big pain and it was a huge relief to most programmers when 32-bit Windows moved to a flat 32-bit virtual address space.
A 'long' pointer in 16-bit Windows was a far pointer (32-bits, the same size as the long type). LPSTR was a typedef for char far* .
The old datatypes survive in 32-bit and now 64-bit Windows largely for source-level compatibility with 16-bit code. Consider it an odd quirk.
|
|
|
|
|
Hello,
I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work...
|
|
|
|
|
|
ok. thx. but i have look about explanation about this command and it seems that it copies string, it doesn´t compare them.... Am i right? How am i suppose to use it?
|
|
|
|
|
if you want to compare them use strcmp or use a CString object to create your string(the "==" operator is overwritten by CString). Direct comparison doesn't works for arrays.
|
|
|
|
|
s1 is CString
then can use
CompareNoCase
Compare
|
|
|
|
|
in fact i think i did not express the problem correctly: i don´t want to egalise two string, but to compare two strings. ( sorry for my english)
|
|
|
|
|
Yes, if S1 and S2 are CString, operators (<, <=, >=, >, ==, and !=) works very well.
If they are char streams, use strcmp function. Operator overloading is not done for char streams.
|
|
|
|
|
in fact i think i did not express the problem correctly: i don´t want to egalise two string, but to compare two strings. ( sorry for my english)
|
|
|
|
|
in fact we understood rightly.
== operaotr compares not equalizes.
|
|
|
|
|
mandanani wrote: == operaotr compares not equalizes
then why does the code:
<br />
c1='aaa bbb ccc';<br />
f1='aaa bbb ccc'; <br />
cout<<c1<<endl;cout<<f1<<endl;<br />
if (c1 == f1) <br />
{a1=1;}<br />
cout<<a1;<br />
<br />
<br />
return on screen:
c
c
0
|
|
|
|
|
I think you have to understand how strings function. What are c1 and f1 ? char pointers, std::string or CString ? Without knowing that we can't really help you.
If these are standard char pointers, you need to use strcpy to be able to store one string in the array (but first, it must be allocated with enough size). Then, you can compare two strings using strcmp function.
Everything has already been told before.
So a code example:
char string1[255];<br />
char string2[255];<br />
<br />
strcpy(string1,"Test");<br />
strcpy(string2,"Test");<br />
if (strcmp(string1,string2) == 0)<br />
cout << "Strings are equal";<br />
else<br />
cout << "Strings are different";
Check the documentation of the functions on MSDN to be sure you understood correctly the concept.
|
|
|
|
|
but what does equalize mean for you ??
and in what does it differ from comparing 2 strings ?
also, don't hesitate to tell what kind of string you use (me know that you use std::string, but most people who replied here didn't know that, hence the CString references) to avoid bad answers
|
|
|
|
|
toxcct wrote: me know that you use std::string
How do you know that ??
|
|
|
|
|
Cedric Moonen wrote: How do you know that ??
I suspect he made an assumption based on the fact the code was using the '==' operator to attempt the comparison, but could obviously be wrong.
|
|
|
|
|
I think the OP was using the == operator with char pointers and that's why it didn't work.
|
|
|
|
|
because he asked a question related 2 posts below
check this[^]
|
|
|
|
|
If somebody is motivated to understand that, i have tried to regroup and order the programme. I hope you will help me.
#include <cstdlib><br />
#include <iostream><br />
using namespace std;<br />
#include<fstream><br />
#include<stdio.h> <br />
#include <time.h><br />
#include <sstream><br />
#include<string><br />
<br />
int main()<br />
{<br />
<br />
<br />
fstream list;<br />
list.open("listfile.txt",ios::in);<br />
<br />
char t;<br />
int i;<br />
string s1;<br />
string s2;<br />
string s3;<br />
string s4;<br />
string s5;<br />
string s6;<br />
string s7;<br />
string s8;<br />
string s9;<br />
string s10;<br />
string s11;<br />
<br />
<br />
getline(list,s1);cout<<s1<<endl;<br />
getline(list,s2);cout<<s2<<endl;<br />
getline(list,s3);cout<<s3<<endl;<br />
getline(list,s4);cout<<s4<<endl;<br />
getline(list,s5);cout<<s5<<endl;<br />
getline(list,s6);cout<<s6<<endl;<br />
getline(list,s7);cout<<s7<<endl;<br />
getline(list,s8);cout<<s8<<endl;<br />
getline(list,s9);cout<<s9<<endl;<br />
getline(list,s10);cout<<s10<<endl;<br />
getline(list,s11);cout<<s11<<endl;<br />
<br />
<br />
time_t date_codee;<br />
tm * date;<br />
ostringstream ostr(ostringstream::out);<br />
date_codee = time(NULL);<br />
date = localtime(&date_codee);<br />
ostr << "clippr-" <br />
<< date->tm_mday <br />
<<"-"<br />
<< date->tm_mon + 1 <br />
<<"-"<br />
<< date->tm_year + 1900<br />
<< ".txt";<br />
<br />
<br />
<br />
int a1=0;<br />
int a2=0;<br />
int a3=0;<br />
int a11=0;<br />
int a4=0;<br />
int a5=0;<br />
int a6=0;<br />
int a7=0;<br />
int a8=0;<br />
int a9=0;<br />
int a10=0;<br />
char c;<br />
char t1;<br />
char t2;<br />
char t3;<br />
char t11;<br />
char t4;<br />
char t5;<br />
char t6;<br />
char t7;<br />
char t8;<br />
char t9;<br />
char t10;<br />
char f;<br />
<br />
<br />
fstream clippr;<br />
clippr.open("clippr.txt",ios::in);<br />
<br />
<br />
fstream fichier1;<br />
fichier1.open(s1.c_str(),ios::in);<br />
<br />
fstream fichier2;<br />
fichier2.open(s2.c_str(),ios::in); <br />
<br />
fstream fichier3;<br />
fichier3.open(s3.c_str(),ios::in);<br />
<br />
fstream fichier11;<br />
fichier11.open(s11.c_str(),ios::in);<br />
<br />
fstream fichier4;<br />
fichier4.open(s4.c_str(),ios::in);<br />
<br />
fstream fichier5;<br />
fichier5.open(s5.c_str(),ios::in);<br />
<br />
fstream fichier6;<br />
fichier6.open(s6.c_str(),ios::in);<br />
<br />
fstream fichier7;<br />
fichier7.open(s7.c_str(),ios::in);<br />
<br />
fstream fichier8;<br />
fichier8.open(s8.c_str(),ios::in);<br />
<br />
fstream fichier9;<br />
fichier9.open(s9.c_str(),ios::in);<br />
<br />
fstream fichier10;<br />
fichier10.open(s10.c_str(),ios::in);<br />
<br />
<br />
string c1;string c2; string c3;<br />
string f1;string f2; string f3;<br />
getline(clippr,c1);<br />
getline(clippr,c1);cout<<c1<<endl;<br />
getline(clippr,c2);cout<<c2<<endl;<br />
getline(clippr,c3);cout<<c3<<endl;<br />
<br />
getline(fichier1,f1);<br />
getline(fichier1,f1);cout<<f1<<endl;<br />
getline(fichier1,f2);cout<<f2<<endl;<br />
getline(fichier1,f3);cout<<f3<<endl;<br />
<br />
<br />
if (c1==f1&&c2==f2&&c3==f3) <br />
{a1=1;}<br />
<br />
<br />
clippr.close();<br />
fichier1.close();<br />
fichier2.close();<br />
fichier3.close();<br />
fichier11.close();<br />
fichier4.close();<br />
fichier5.close();<br />
fichier6.close();<br />
fichier7.close();<br />
fichier8.close();<br />
fichier9.close();<br />
fichier10.close();<br />
<br />
if (a1==1) {cout<<"fichier1 is not clippr"<<endl; }<br />
if (a2==1) {cout<<"fichier2 is not clippr"<<endl; }<br />
if (a3==1) {cout<<"fichier3 is not clippr"<<endl; }<br />
if (a11==1){cout<<"fichier11 is not clippr"<<endl; }<br />
if (a5==1) {cout<<"fichier5 is not clippr"<<endl; }<br />
if (a4==1) {cout<<"fichier4 is not clippr"<<endl; }<br />
if (a6==1) {cout<<"fichier6 is not clippr"<<endl; }<br />
if (a7==1) {cout<<"fichier7 is not clippr"<<endl; }<br />
if (a8==1) {cout<<"fichier8 is not clippr"<<endl; }<br />
if (a9==1) {cout<<"fichier9 is not clippr"<<endl; }<br />
if (a10==1){cout<<"fichier10 is not clippr"<<endl; }<br />
<br />
<br />
if (a1==0) {cout<<"fichier1 is clippr"<<endl;<br />
rename(s1.c_str(), ostr.str().c_str());}<br />
<br />
<br />
<br />
cin>>t1;}<br />
|
|
|
|
|
very bad thing to post a huge block of code and tell to anyone to see what's wrong with it...
you must post relevant samples, and try to understand which are the incriminated lines.
and use your debugger if you can
|
|
|
|
|
if(strcmp(s1,s2)==0)
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
s1 and s2 are std::strings...
|
|
|
|