g++ vim
wbgxx
Posts
-
C++ Programming -
find a effictive way!!could you give me detail??Thanks
-
find a effictive way!!for example there is a four bits integer 1122, if someone guess and inout 1234, because 1 and 2 are in 1122, and the position is same, the computer will tell you that you are right with two numbers and they are 1 and 2; as follows is my program, I thinnk they are too complex , could some tell me a simple algorithm, thinks in advantage
#include <stdio.h> #include <stdlib.h> int main() { int data1 = 1234; int data2; int gewei1, shiwei1, baiwei1, qianwei1; int gewei2, shiwei2, baiwei2, qianwei2; int count = 0; gewei1 = data1%10; shiwei1 = (data1%100)/10; baiwei1 = (data1%1000)/100; qianwei1 = data1 /1000; int arr1[4] = {qianwei1, baiwei1, shiwei1, gewei1}; printf("Please Enter a interger:"); scanf("%d", &data2); gewei2 = data2%10; shiwei2 = (data2%100)/10; baiwei2 = (data2%1000)/100; qianwei2 = data2 /1000; int arr2[4] = {qianwei2, baiwei2, shiwei2, gewei2}; for (int i=0; i<4; i++) { if(arr1[i] == arr2[i]) { printf("%d ", arr1[i]); count++; } else continue; } printf("the same number is %d ", count); return 0; }
-
why segmentation fault !wonderful! I see, thanks in advance!
-
why segmentation fault !thanks ! but I still have question why this can be run
#include <iostream.h>
#include <cstring>
void swap(char *,char *);
int main()
{char str1[20]="hello",str2[20]="how are you ";
char pt[20];
cout<<"str1"<<" "<<str1<<endl;
cout<<"str2"<<" "<<str2<<endl;
strcpy(pt,str1);
strcpy(str1,str2);
strcpy(str2,pt);
cout<<"str1"<<" "<<str1<<endl;
cout<<"str2"<<" "<<str2<<endl;
return 0;
} -
hex calculatorIn my opinion Google is a good way to study!
-
why segmentation fault !I want to swap two string
#include <stdio.h>
#include <string.h>
void swap(char *a1, char *a2)
{
char ch[20];
if (a1 != NULL || a2 != NULL)
{
strcpy(ch, a1);
strcpy(a1, a2);
strcpy(a2, ch);} else return ;
}
int main()
{
char *a1 = "hello";
char *a2 = "world";
printf("Before the swap a1=%s, a2=%s", a1, a2);
swap(a1, a2);
printf("After the swap a1=%s, a2=%s", a1, a2);
return 0;
} -
Difference between VC6 and VS 2008.I think there is not many differents ,I now in China and many company still use vs6
-
Learning LinuxI think the first to do install a linux OS
-
Can someone give a detail of this sample coder why the result is 9,and not 4??#include <iostream.h>
int main()
{
int x=1,y;
y= ++x*++x;
cout << x << endl;
cout << y <<endl;
return 0;
} -
Can someone give a detail of " shortest-seek -time-First algorithm" some coder is the betterRT
-
could some one give me a detail of this the result??I don not know why,more detail more bettercout << (unsigned int)(&struct2.struct1) - (unsigned int)(&struct2)
<< endl;and what is (unsigned int)(&struct2.struct1)means?
-
a question of struct copys#include <iostream.h>
struct structA
{
int iMember;
char *cMember;
};int main(int argc, char* argv[])
{
structA instant1,instant2;char c = 'a';
instant1.iMember = 1;
instant1.cMember = &c;
instant2 = instant1;cout << *(instant1.cMember) << endl;
*(instant2.cMember) = 'b';
cout << *(instant1.cMember) << endl; //I want to know why change instant2 and the instant1 change!getchar();
} -
could some one give me a detail of this the result??I don not know why,more detail more better#include <iostream>
using namespace std;
#pragma pack(8)struct example1
{
short a;
long b;
};struct example2
{
char c;
example1 struct1;
short e;
};#pragma pack()
int main()
{
example2 struct2;
cout << sizeof(example1) << endl; //8
cout << sizeof(example2) << endl; //16
cout << (unsigned int)(&struct2.struct1) - (unsigned int)(&struct2)
<< endl; //4getchar();
}
-
My progremmer can't run,why??sorry ,I don't know why
-
My progremmer can't run,why??#include <iostream>
#include <string>
using namespace std;class CBuffer
{
char * m_pBuffer;
int m_size;
public:
CBuffer()
{
m_pBuffer=NULL; }
~CBuffer()
{
Free();
}
void Allocte(int size) (3) {
m_size=size;
m_pBuffer= new char[size];
}
private:
void Free()
{
if(m_pBuffer!=NULL)
{
delete m_pBuffer;
m_pBuffer=NULL;
}
}
public:
void SaveString(const char* pText) const
{
strcpy(m_pBuffer, pText);
}
char* GetBuffer() const
{
return m_pBuffer;
}
};int main ()
{
CBuffer buffer1;
buffer1.SaveString("Microsoft");
printf("%s", buffer1.GetBuffer());
return 0;
} -
my strcpy funcution!sorry,I can not test it ,can you tell me how to do it ?
-
my strcpy funcution!char *my_strcpy(char *p1, char *p2)
{
if (p2 == NULL )
return p1;
if (p1 == NULL)
return 0;
else
{char \*pp1 = p1; char \*pp2 = p2; while (p2 != '\\0') { \*p1++ = \*p2++; } \*pp1 = '\\0'; } return p1;
}
-
my strcpy funcution!char *my_strcpy(char *p1, char *p2) { if (p2 == NULL ) return p1; if (p1 == NULL) return 0; else { char *pp1 = p1; char *pp2 = p2; while (p2 != '\0') { *p1++ = *p2++; } *pp1 = '\0'; } return p1; } Is there something wrong in my function and why? Thanks in advantage
-
find a sulution!Yeah,thanks