c-strings Questions

1

Solved

I'm looking for a clean and simple way to read a null-terminated C string from a file or file-like object in Python. In a way that doesn't consume more input from the file than it needs, or pushes ...
Hessite asked 25/9, 2015 at 4:40

2

Solved

Can anyone explain what is happening in this code? #include <stdio.h> void f(const char * str) { printf("%d\n", str[4]); } int main() { f("\x03""www""\x01""a""\x02""pl"); f("\x03www...
Aetna asked 28/8, 2015 at 17:19

3

Solved

So C++ 14 introduced a number of user-defined literals to use, one of which is the "s" literal suffix, for creating std::string objects. According to the documentation, its behavior is exactly the ...
Shanahan asked 20/8, 2015 at 10:58

4

Solved

The following code is from K&R textbook, page number 71: val =10.0*val+s[i] -'0' What does s[i] -'0' mean here?
Womack asked 18/7, 2015 at 10:22

2

While using gets() in my code, the compiler shouts warning: the 'gets' function is dangerous and should not be used.` and warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:6...
Seoul asked 17/6, 2015 at 11:48

2

Why I can't define an array char **pp={ "123", "456", "789" }; But I can define it as a char*[] ,and send it to a function that will accept it as a char ** char *pp[]={ "123", "456", "789" }; f...
Gaona asked 29/5, 2015 at 14:23

3

Solved

in c++ is this a good practice to initialize char array with string? such as: char* abc = (char *) ("abcabc"); I see a lot of these in my co-worker's code. Should I change it to the right practi...
Alluvion asked 12/5, 2015 at 17:47

3

Solved

Consider the code: struct Foo { const char str[] = "test"; }; int main() { Foo foo; } It fails to compile with both g++ and clang++, spitting out essentially error: array bound cannot be...
Fluorine asked 12/4, 2015 at 18:45

4

Solved

I am attempting to write a function that will remove all characters from an array, except for '+', '-', '*', '/', and numbers. This is the code I came up with: void eliminateJunk(char string[MAX])...
Rosinweed asked 8/4, 2015 at 10:0

7

Solved

I am reading "Write Great Code Volume 2" and it shows the following strlen impelementation: int myStrlen( char *s ) { char *start; start = s; while( *s != 0 ) { ++s; } return s - start; } ...
Rna asked 5/7, 2011 at 14:30

3

Solved

I need to extract the text between 2 string patterns in c. Example: aaaaaa<BBBB>TEXT TO EXTRACT</BBBB>aaaaaaaaa PATTERN1=<BBBB> PATTERN2=</BBBB> Thanks.
Moll asked 11/7, 2014 at 10:58

2

Solved

A function returning a copy of an integer literal int number() { return 1; } can be easily converted to a plain compile-time expression using the keyword constexpr. constexpr int number() { ret...
Marathon asked 21/3, 2014 at 2:20

5

Solved

I tried using strncmp but it only works if I give it a specific number of bytes I want to extract. char line[256] = This "is" an example. //I want to extract "is" char line[256] = This is "also" ...
Pergrim asked 24/10, 2013 at 1:44

18

Solved

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.
Upu asked 20/9, 2008 at 20:45

5

Solved

Why does this code produce runtime issues: char stuff[100]; strcat(stuff,"hi "); strcat(stuff,"there"); but this doesn't? char stuff[100]; strcpy(stuff,"hi "); strcat(stuff,"there");
Norford asked 16/9, 2013 at 23:20

5

Solved

I have this code: char *name = "George" if(name == "George") printf("It's George") I thought that c strings could not be compared with == sign and I have to use strcmp. For unknown reason when...
Jankell asked 22/7, 2013 at 7:13

4

Solved

How would one go about converting a C char** to a C++ vector? Is there some built-in functionality one can utilize to do this, or is it better to accomplish it through a series of iterative s...
Bodiless asked 29/3, 2013 at 18:50

3

Possible Duplicate: What is the proper function for comparing two C-style strings? My match condition doesn't work! Can someone advise how to compare to C-style strings? void saveDat...
Tristich asked 25/11, 2012 at 7:56

2

Solved

I have a function which accepts one argument of type char*, like f("string"); If the string argument is defined by-the-fly in the function call, how can macros be expanded within t...
Floro asked 18/10, 2012 at 16:5

3

Solved

No guides I've seen seem to explain this very well. I mean, you can allocate memory for a char*, or write char[25] instead? What's the difference? And then there are literals, which can't be manip...
Burlington asked 4/10, 2012 at 0:48

1

Solved

I have a constant defined: #define MAX_STR_LEN 100 I am trying to do this: scanf("%" MAX_STR_LEN "s", p_buf); But of course that doesn't work. What preprocessor trick can be use to convert t...
Caril asked 29/9, 2012 at 0:51

5

Solved

Say I wanted to duplicate a string then concatenate a value to it. Using stl std::string, it's: string s = "hello" ; string s2 = s + " there" ; // effectively dup/cat in C: char* s = "hello" ;...
Afroasiatic asked 25/9, 2012 at 21:7

5

Solved

Possible Duplicate: What is the difference between char s[] and char *s in C? Question about pointers and strings in C I'm reading about the strings in C and I'm confused. I can "dec...
Bjork asked 25/8, 2012 at 12:0

4

Solved

I have a C string that looks like "Nmy stringP", where N and P can be any character. How can I edit it into "my string" in C?
Sprag asked 13/11, 2009 at 0:5

3

Solved

I'm writing a string class that is similar to std::string for a homework assignment, but I cannot figure out how to return a C string that does not cause a memory leak and is guaranteed to stay the...
Jonjona asked 4/7, 2012 at 23:30

© 2022 - 2024 — McMap. All rights reserved.