dotnet
07/11/2007, 14:45
Merhabalar Efendim,
Ufak bir okul ödevi için ufak bir ödev yapıyorum, ve ufak bir class'ım var.
Yaptığı şey ise şu, benim constructor'da belirttiğim String'i alıp bir integer pointer'ın içerisine bit bit yazmak.
mystring.h dosyası
#ifndef MYSTRING_H
#define MYSTRING_H
#include <iostream>
#include <string.h>
using namespace std;
/**
@author İsmail Taha AYKAÇ <ismail@ieee.org>
*/
class MyString{
public:
MyString();
string str;
int *binChars;
char *buf;
char *strToChar();
int *charToBin();
};
#endif
mystring.cc dosyası
#include "mystring.h"
MyString::MyString()
{
str = "Watson, come here, I want you.";
// memset( binChars, 0, str.size() * 8 );
// binChars = charToBin();
char *a = strToChar();
}
char* MyString::strToChar()
{
char buff[30]; //= (char *)malloc(str.length() + 1);
memset( buff, '\0', 30 );
//int size = a.size();
str.copy(buff, str.size());
cout << sizeof(buff);
return &buff[0];
}
int *MyString::charToBin()
{
int i = 0, j, *retValue;
char bufChar, *charSet;
charSet = strToChar();
while(*charSet)
{
bufChar = *charSet;
for(j=0;j<8; i++, j++)
{
bufChar = bufChar << 1;
retValue[i] = (bufChar & 0x80)/128;
}
charSet++;
}
return retValue;
}
MyString Class'ının charToBin metodu, çalıştığında veya ben binChars pointerımı bir yerde kullandığımda
Segmentation Fault (Core Dumped)
hatası veriyor.
Not: compilor olara g++ kullanıyorum
Bir not daha: aynı kod bir şekilde çalışıyordu, bir şeyler yapdım çalışmaz oldu, deli oldum valla :D, yedek almadığıma pişman oldum.
Ufak bir okul ödevi için ufak bir ödev yapıyorum, ve ufak bir class'ım var.
Yaptığı şey ise şu, benim constructor'da belirttiğim String'i alıp bir integer pointer'ın içerisine bit bit yazmak.
mystring.h dosyası
#ifndef MYSTRING_H
#define MYSTRING_H
#include <iostream>
#include <string.h>
using namespace std;
/**
@author İsmail Taha AYKAÇ <ismail@ieee.org>
*/
class MyString{
public:
MyString();
string str;
int *binChars;
char *buf;
char *strToChar();
int *charToBin();
};
#endif
mystring.cc dosyası
#include "mystring.h"
MyString::MyString()
{
str = "Watson, come here, I want you.";
// memset( binChars, 0, str.size() * 8 );
// binChars = charToBin();
char *a = strToChar();
}
char* MyString::strToChar()
{
char buff[30]; //= (char *)malloc(str.length() + 1);
memset( buff, '\0', 30 );
//int size = a.size();
str.copy(buff, str.size());
cout << sizeof(buff);
return &buff[0];
}
int *MyString::charToBin()
{
int i = 0, j, *retValue;
char bufChar, *charSet;
charSet = strToChar();
while(*charSet)
{
bufChar = *charSet;
for(j=0;j<8; i++, j++)
{
bufChar = bufChar << 1;
retValue[i] = (bufChar & 0x80)/128;
}
charSet++;
}
return retValue;
}
MyString Class'ının charToBin metodu, çalıştığında veya ben binChars pointerımı bir yerde kullandığımda
Segmentation Fault (Core Dumped)
hatası veriyor.
Not: compilor olara g++ kullanıyorum
Bir not daha: aynı kod bir şekilde çalışıyordu, bir şeyler yapdım çalışmaz oldu, deli oldum valla :D, yedek almadığıma pişman oldum.