Pavel
im new in cpp :D
Destructor is called automatically when you delete the object. You should delete the pointer you allocated with new. And do that outside the class, not from a member function Or better yet use std::unique_pointer
MRT
thanks
Aakash
//class class HandShakeThreadClass { public: HandShakeThreadClass(SOCKET sock) : sock(sock) { _data = ""; StartInternalThread(); } ~HandShakeThreadClass() { closesocket(sock); pthread_cancel(_thread); (void)pthread_join(_thread, NULL); return; } /** Returns true if the thread was successfully started, false if there was an error starting the thread */ bool StartInternalThread() { return (pthread_create(&_thread, NULL, InternalThreadEntryFunc, this) == 0); } protected: virtual void InternalThreadEntry() { int buffLength = 512; std::vector<char> buffer(buffLength); int socket_res; bool is_active = true; // u_long iMode = 1; ! //ioctlsocket(sock, FIONBIO, &iMode);//set client socket to none blocking int ReceiveTimeout = 5000; setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&ReceiveTimeout, sizeof(ReceiveTimeout)); do { printf("Repeat socket recv \n"); socket_res = recv(sock, &buffer[0], buffer.size(), 0); if (socket_res == SOCKET_ERROR) { // is_active = false; continue; } else { // } continue; } while (is_active); // i want to cancle thread and delete this class ! this->~HandShakeThreadClass(); return; }; private: static void* InternalThreadEntryFunc(void* This) { ((HandShakeThreadClass*)This)->InternalThreadEntry(); return NULL; } pthread_t _thread; }; #endif
#include <iostream> class X { public: X() { std::cout << "Constructor:X\n"; } ~X() { std::cout << "Destructor :X\n"; } }; int main() { X *x = new X; //Instance of Class delete x; return 0; }
Xudoyberdi
https://pastebin.com/iFcM0iQH
Xudoyberdi
Anyone can guide me in documentation or something related to this segmentation fault.
Vlad
There's no silver bullet
Vlad
And what do you think this does? scanf("\0", &numbers[j]);
Vlad
FTW
Vlad
You sure you should be inputing goddam pointers from the console?
Vlad
I dont think so
Ali
It's good group
Ali
Thanx
Anonymous
/get best-book
Anonymous
/get
Anonymous
/get cbook
Anonymous
Thank you
Cem
Hi everyone I am managing with a project that called "passwords". There some text files include passwords line by line. I have to write a code that sorting those passwords using merge sort. I couldn't find anything in the internet. Is there anyone who can help me?
Cem
The program is in C language by tthe way.
Cem
I know the merge sort but i couldn't implement it to the text file.
Xudoyberdi
And what do you think this does? scanf("\0", &numbers[j]);
Sorry, zero charater should have been string specifier. (%s)
Vlad
Sorry, zero charater should have been string specifier. (%s)
Either way you'd have to allocate memory for each string first
Vlad
And scanf("%s", str); is unsafe
Vlad
No buffer overrun checking or anything
Vlad
I thought it was possible.
And what will you do with an arbitrary pointer that user inputed?
Vlad
It doesn't make any sense
Vlad
Oh yeah, 0xdead will be all right
Xudoyberdi
Okay, sorry.
Anonymous
https://pastebin.com/iFcM0iQH
The string array is a vector of pointers, and probably not pointing to valid memory. The pointers should be aimed at either a static char buffer or a dynamically allocated char buffer. The char *argv[] argument to main(int argc, char *argv[]) has space allocated by the operating system but your string array will have to be prepared yourself. Somebody asked about thread cleanup? https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cleanup_pop.html
Anonymous
char *strings[cnt]; for(int i = 0; i < cnt; i++) { char buffer[1024]; scanf("%1023[^\n]", buffer); int junk = getchar(); // assuming it was '\n' strings[i] = strdup(buffer); } /* ... */ for(int i = 0; i < cnt; i++) { free(strings[i]); strings[i] = NULL; }
Manideep
I am absolute beginner to programming can any one help me..
The
#include<stdio.h> const int n=3; void matrix(int a[n][n]) { int i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d",a[i][j]); } printf("\n"); } } void transpose(int a[n][n]) { int i,j,temp; for(i=0;i<n;i++) { for(j=0;j<i;j++) { temp=a[i][j]; a[i][j]=a[j][i]; a[j][i]=temp; } } } void matrixrotation(int a[n][n]) { int i,j,temp; for(j=0;j<n/2;j++) { for(i=0;i<n;i++) { temp=a[i][j]; a[i][j]=a[i][n-j-1]; a[i][n-j-1]=temp; } } } int main() { int x[3][3]={{1,2,3},{4,5,6},{7,8,9}}; printf("original matrix \n"); matrix(x); transpose(x); matrixrotation(x); printf("matrix rotation \n"); matrix(x); }
Pavel
I am absolute beginner to programming can any one help me..
Hi, ask your questions right away. People usually don't answer to vague messages asking for help not specifying what exact help is needed. dontasktoask.com
Gaurav
Okay
Anonymous
struct node *current = start->next What" current" will contain if it is variable of type struct node? I have rounded the options to 2 from 6, A. Address of 2nd Node B. Address Field of 2nd Node My question is , What's the difference between address and address field?
Anonymous
#include <stdio.h> typedef struct node_ { struct node_ *next; } node_t; int main() { node_t head, nodes[5]; for(int i = 0; i+1 < 5; i++) nodes[i].next = &nodes[i+1]; nodes[4].next = NULL; head.next = &nodes[0]; int k = 1; for(node_t *n = &head; n != NULL; n = n->next) { printf("#%d : next = %p\n", k++, n->next); } return 0; }
SANDEEP
A square mask opening is used to create a cavity in a silicon wafer. Suppose the thickness of the wafer is 500 µm (t) which has a square window opening of side 1 mm (w) as shown in the following figure. The etch rate on <100> surface is 2 µm/min (T). Ignoring the etch rate on <111> surface. What is the size of opening on the back side of the wafer if etching is longer than 4.5 hours? Options are:- 0.286 mm 1.714 mm 0.714 mm 0.357 mm 0.643 mm
klimi
:)
damn...
klimi
that damn smile
Vedant
that damn smile
When the trouble began!
Prince Of Persia
Is there any difference between compiling C with G++ or GCC?
Alex
Is there any difference between compiling C with G++ or GCC?
yes. g++ compiles it as c++ sources always. gcc depends on file extension
Pavel
How to start programming and where to start with....
Choose a language (doesn't much matter which one, you can switch to another language later when will understand what language you need). Find a book or tutorials. Install a compiler and some editor or IDE. Follow the tutorials. Try to understand what you're doing. Google if encounter problems. Try to write some simple app yourself.
MRT
hey
MRT
typedef std::unique_ptr<HandShakeThreadClass> handShakePTR; std::vector<handShakePTR> handShakeClients; handShakeClients.push_back(handShakePTR(new HandShakeThreadClass(ClientSocket)));
MRT
for (auto& client : handShakeClients) { if((*client).itsActive())printf("yes is active"); }
Prince Of Persia
yes. g++ compiles it as c++ sources always. gcc depends on file extension
Is there any difference between C and C++ (same code)
Prince Of Persia
yes
Why?
Alex
Why?
cause c and c++ are difference languages. check sizeof('a') in C and C++
Prince Of Persia
Why this happened?
Alex
cause c and c++ are difference languages. check sizeof('a') in C and C++
Pavel
Why this happened?
Different languages as Alex already mentioned, they have different standards
Anonymous
Char: 8 bits Int: 16 (when specified) or 32 Float: 32 Double: 64 Long double: 96
crt
Why this happened?
https://en.cppreference.com/w/cpp/language/sizeof
Anonymous
(for C)
Pavel
But char length is 8 bit
sizeof returns size in chars (not in bits), in C I believe 'a' is int, which has have sizeof 4
crt
https://en.cppreference.com/w/cpp/language/sizeof
sizeof(char), sizeof(char8_t), sizeof(signed char),sizeof(unsigned char), and sizeof(std::byte) are always equal to 1.