c-strings

Is there anyway to create null terminated string in Go?

不打扰是莪最后的温柔 提交于 2019-12-05 01:32:31
Is there anyway to create null terminated string in Go? What I'm currently trying is a:="golang\0" but it is showing compilation error: non-octal character in escape sequence: " Spec: String literals: The text between the quotes forms the value of the literal, with backslash escapes interpreted as they are in rune literals (except that \' is illegal and \" is legal), with the same restrictions. The three-digit octal ( \nnn ) and two-digit hexadecimal ( \xnn ) escapes represent individual bytes of the resulting string; all other escapes represent the (possibly multi-byte) UTF-8 encoding of

scanf() does not read input string when first string of earlier defined array of strings in null

你。 提交于 2019-12-04 20:02:00
I defined an array for strings. It works fine if I define it in such a way the first element is not an empty string. When its an empty string, the next scanf() for the other string stops reading the input string and program stops execution. Now I don't understand how can defining the array of strings affect reading of input by scanf() . char *str_arr[] = {"","abc","","","b","c","","",""}; // if first element is "abc" instead of "" then works fine int size = sizeof(str_arr)/sizeof(str_arr[0]); int i; printf("give string to be found %d\n",size); char *str; scanf("%s",str); printf("OK\n");

Why use c strings in c++?

醉酒当歌 提交于 2019-12-04 17:01:10
问题 Is there any good reason to use C-strings in C++ nowadays? My textbook uses them in examples at some points, and I really feel like it would be easier just to use a std::string. 回答1: The only reasons I've had to use them is when interfacing with 3rd party libraries that use C style strings. There might also be esoteric situations where you would use C style strings for performance reasons, but more often than not, using methods on C++ strings is probably faster due to inlining and

Determine #defined string length at compile time

梦想与她 提交于 2019-12-04 10:00:47
问题 I have a C-program (an Apache module, i.e. the program runs often), which is going to write() a 0-terminated string over a socket, so I need to know its length. The string is #defined as: #define POLICY "<?xml version=\"1.0\"?>\n" \ "<!DOCTYPE cross-domain-policy SYSTEM\n" \ "\"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n" \ "<cross-domain-policy>\n" \ "<allow-access-from domain=\"*\" to-ports=\"8080\"/>\n" \ "</cross-domain-policy>\0" Is there please a way, better than using

How to determine if strings are equal in Objective C?

♀尐吖头ヾ 提交于 2019-12-04 05:05:05
I read a string from a JSON result as follows: NSString *strResult = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; I then try to determine if the string is equal to the value "N" if ([strResult isEqualToString:@"N"]) { [lblImageOK setHidden:YES]; } else { [lblImageOk setHidden:NO]; } The if statement allways returns the else part, even though the result is "N". They both have the same value but the statement returns false always. I found a way to clean the string and then check if they are equal. NSString *strResult = [[NSString alloc]

C-String array initialization - is this mutable? [duplicate]

给你一囗甜甜゛ 提交于 2019-12-04 02:35:52
This question already has answers here : Closed 7 years ago . Possible Duplicate: Modifying C string constants? Pointer to const char vs char array vs std::string I know I'm probably beating the dead horse with this question, but I'm a little confused and I haven't managed to find an exact answer on SO or google (that I'm confident is right - there's just too much information on C-strings to sift through). Also, I've tagged it C++ because that's what I'm interested in, even though we're talking about C-style strings specifically. In this situation: char const a* = "hello"; char const b[] =

Implementing `strtok` whose delimiter has more than one character

拜拜、爱过 提交于 2019-12-04 02:11:26
问题 Code snippet: char str[] = "String1::String2:String3:String4::String5"; char *deli = "::"; char *token = strtok(str,deli); while(token != NULL) { printf("Token= \"%s\"\n", token); token=strtok(NULL,deli); } The above code snippet produces the output: Token="String1" Token="String2" Token="String3" Token="String4" Token="String5" but I want the output to be: Token="String1" Token="String2:String3:String4" Token="String5" I know that I am not getting the expected output because each character

NSString cString is Deprecated. What is the alternative?

强颜欢笑 提交于 2019-12-04 02:02:02
I've got another newbie question. I've written a piece of code that converts a NSString to NSMutableData in order to simulate a webService result. It turns out however that cString is deprecated. Can you help me replace it? Here's my code. NSString *testXMLDataString = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" etc.... "</SOAP-ENV:Envelope>"; //Replace webData Received from the web service with the test Data NSMutableData *testXMLData = [NSMutableData dataWithBytes:[testXMLDataString cString] length:[testXMLDataString length]]; [webData setData:testXMLData]; Get the raw bytes from the

Crash in CAtlStringMgr::GetInstance under Windows XP

孤街醉人 提交于 2019-12-03 16:57:54
I've written a DLL that creates an ATL CString object. I compile it with Visual Studio 2015 using the "Visual Studio 2015 - Windows XP (v140_xp)" platform toolset. The DLL is loaded using LoadLibrary/GetProcAddress. It crashes under Windows XP in CAtlStringMrg::GetInstance when allocating the string object. The same application works well on Windows Vista and later. Here is the disassembly: static IAtlStringMgr* GetInstance() { #pragma warning(push) #pragma warning(disable: 4640) static CWin32Heap strHeap( ::GetProcessHeap() ); 1003B100 mov eax,dword ptr fs:[0000002Ch] 1003B106 mov ecx,dword

In C, can I initialize a string in a pointer declaration the same way I can initialize a string in a char array declaration?

断了今生、忘了曾经 提交于 2019-12-03 12:25:32
问题 Do these two lines of code achieve the same result? If I had these lines in a function, is the string stored on the stack in both cases? Is there a strong reason why I should use one over the other, aside from not needing to declare the null terminator in the first line of code? char s[] = "string"; char* s = "string\0"; 回答1: No, those two lines do not achieve the same result. char s[] = "string" results in a modifiable array of 7 bytes, which is initially filled with the content 's' 't' 'r'