sizeof

Memory Leaks in C Linked List

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been working on a project for school (Due tonight!), and I'm having some serious memory issues. I'm fairly new to C and am still being thrown for a loop when it comes to mallocing pointers and whatnot, so I could really use some help. The code is as follows. The order of the files is LinkedLists.h (Header for LinkedList module), LinkedLists.c (LinkedList module), and TestList.c (Main module). /****************************************************************************** * Base struct to contain data structure element information:

Find the size of reserved memory for a character array in C

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to learn C and as a start, i set off writing a strcpy for my own practice. As we know, the original strcpy easily allows for security problems so I gave myself the task to write a "safe" strcpy. The path I've chosen is to check wether the source string (character array) actually fits in the destination memory. As I've understood it, a string in C is nothing more than a pointer to a character array, 0x00 terminated. So my challenge is how to find how much memory the compiler actually reserved for the destination string? I tried:

using std::unique_ptr with allocators

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I was trying my hand with allocators this time & felt that there were many chances of leaking the resources. So I thought what if I used std::unique_ptr to handle them. I tried my hand with a std::vector 's allocator. My code goes like this :- // allocator #include <iostream> #include <vector> #include <memory> using namespace std ; class X { int x , ID ; static int i ; public : X () { cout << "constructing " ; ID =++ i ; cout << "ID=" << ID << '\n' ; } X ( int a ) { x = a ; cout << "constructing " ; ID =++ i ; cout << "ID=" << ID

Read files separated by tab in c

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am really new to C, and the reading files thing drives me crazy... I want read a file including name, born place and phone number, etc. All separated by tab The format might be like this: Bob Jason Los Angeles 33333333 Alice Wong Washington DC 111-333-222 So I create a struct to record it. typedef struct Person{ char name[20]; char address[30]; char phone[20]; } Person; I tried many ways to read this file into struct but it failed. I tired fread: read_file = fopen("read.txt", "r"); Person temp; fread(&temp, sizeof(Person), 100, read_file);

When should we use sizeof with and without parentheses [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: What does sizeof without () do? [duplicate] 5 answers typedef struct rem{ int addr; char addrbuf[32]; } foo; Both of these codes return the same results foo addr; printf("size is: %d\n",sizeof addr); printf("size is: %d\n",sizeof (foo)); size is: 36 size is: 36 But when should we use sizeof with and without parentheses? 回答1: When using sizeof with a type, you need parentheses around the type. When using it with an expression, you don't. But you can of course include them in this case as well, and you

Why is this happening with the sizeof operator when comparing with a negative number? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: sizeof() operator in if-statement 5 answers What's really happening here? The output now is "False": #include int main() { if (sizeof(int) > any_negative_integer) printf("True"); else printf("False"); return 0; } If I change it to: if (sizeof(int) the output is "True". Update: the same question has already been asked, I could not find it before asking. 回答1: sizeof returns size_t which is unsigned and so -1 is being converted to a very large unsigned number. Using the right warning level would have

Is it possible to activate TCP keepalive on Apple iOS devices

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Apple device === Router === WiFi module Apple device(iPhone) is connecting to WiFi module port 2000 with TCP connection. I want to activate TCP keepalive packet sending on Apple device to find out when TCP connection to WiFi module is lost (module is switched off). My stream setup CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)CFBridgingRetain(moduleIPaddress), port2000, &readStream, &writeStream); outputStream = (NSOutputStream *)CFBridgingRelease(writeStream); inputStream =

OpenSSL AES 256 CBC via EVP api in C

匿名 (未验证) 提交于 2019-12-03 01:17:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What I am trying to do: Write a program in C that opens a file of arbitrary size and reads its contents. Once The contents are read it will encrypt them in AES 256 CBC and save the ciphertext to a file called ciphertext. Once this is saved it will close both files. Then will open the cipher text from the file that was just saved and decrypt the cipher text and save it to a file called decrypted. My Problem: It seems to never decrypt my cipher text. I get garbage, I have no idea what I am doing wrong. Please help. #include #include #include

How can I print the result of sizeof() at compile time in C?

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I print the result of sizeof() at compile time in C? For now I am using a static assert (home brewed based on other web resources) to compare the sizeof() result to various constants. While this works... it is far from elegant or fast. I can also create an instance of the variable/struct and look in the map file but this is also less elegant and fast than a direct call/command/operator. Further, this is an embedded project using multiple cross-compilers... so building and loading a sample program to the target and then reading out a

Check Windows version

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How I can check in C++ if Windows version installed on computer is Windows Vista and higher (Windows 7)? 回答1: Similar to other tests for checking the version of Windows NT: OSVERSIONINFO vi; memset (&vi, 0, sizeof vi); vi .dwOSVersionInfoSize = sizeof vi; GetVersionEx (&vi); if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT && vi.dwMajorVersion >= 6) 回答2: All the answers in this thread point you to using GetVersion or GetVersionEx for this test, which is incorrect . It seems to work, but it is risky. The primary source of appcompat problems for