c-strings Questions

3

Solved

I am making a program where I need to use a function which stores a tokens of a string in a vector. The function did not work properly so I tried the function on a smaller program. Of course, I use...
Desert asked 25/6, 2020 at 8:16

4

Solved

I know that here are some explanations about the difference between p++, ++p and p+1 but I couldn't understand it clearly yet, especially when it's not working with that function: void replace(cha...

4

Solved

This may be simple question, but why does a const char* not need a memory address to point to? Example: const char* a = "Anthony"; and not: const char *a = // Address to const char like any ...
Ultranationalism asked 18/4, 2020 at 8:2

9

Solved

In an introductory course of C, I have learned that while storing the strings are stored with null character \0 at the end of it. But what if I wanted to print a string, say printf("hello") althoug...
Entebbe asked 7/2, 2020 at 12:54

9

Solved

My course taught me that char*s are static/read only so I thought that would mean you can't edit them after you have defined them. But when I run: char* fruit = "banana"; printf("fruit is %s\n", f...
Jaclynjaco asked 31/5, 2017 at 21:4

1

Solved

Suppose I have the following code: #include <iostream> #include <string> #include <iomanip> using namespace std; // or std:: int main() { string s1{ "Apple" }; cout << b...
Phenetidine asked 26/12, 2019 at 15:53

2

Solved

I want to define a multidimensional C-string array, initialized by several string literals. In C I would do the following: #include <stdio.h> const char *strArr[2][1] = { {"foo"}, {""}}; i...
Aggravation asked 27/11, 2019 at 18:36

4

Solved

I understand that strings in C are just character arrays. So I tried the following code, but it gives strange results, such as garbage output or program crashes: #include <stdio.h> int main...
Haig asked 23/10, 2019 at 15:17

5

Solved

I'd like to know what the result would be if we print a string that contains "%s" in its content? I tried printing it as "hi%s". char *ptr="hi%s"; printf(ptr); I expected the output to be as "h...
Internationalism asked 16/7, 2019 at 14:29

3

Solved

I'm writing a simple application in C, which I would like to publish under BSD license. One part of the application is responsible for printing out information about the program to its users. Howev...
Animosity asked 28/12, 2014 at 19:25

4

Solved

From CString to char*, ReleaseBuffer() must be used after GetBuffer(). But why? What will happen if I don't use ReleaseBuffer() after GetBuffer()? Can somebody show me an example? Thanks.
Fluffy asked 26/2, 2010 at 15:6

4

Solved

I am from Python background and recently learning C++. I was learning a C/C++ function called memset and following the online example from website https://www.geeksforgeeks.org/memset-in-cpp/...
Liriodendron asked 5/6, 2019 at 15:13

3

I'm a beginner at C, please don't bash me. So, I have this function that gets the mask of an "ip/mask" type of string: char *getmask(char n[]) { char x[255] = { 0 }; strcpy(x, n); char *mask; ...
Vaudois asked 31/10, 2016 at 1:39

5

Solved

I have an array of strings with a given size, without using any memory allocation, how do I append something into it? Say I run the code, its waiting for something you want to enter, you enter "bo...
Siphon asked 17/4, 2015 at 12:37

2

Solved

Yesterday, I had my Unit Test. One of the programs was to copy strings and find out its length without the string functions. This was the code I wrote: #include <stdio.h> int main(){ char ...
Spandex asked 3/4, 2019 at 5:36

2

What's the most direct way to use a C string as Rust's Path? I've got const char * from FFI and need to use it as a filesystem path in Rust. I'd rather not enforce UTF-8 on the path, so convert...
Polyvalent asked 21/9, 2017 at 11:22

7

Solved

In one of my programs, I have to interface with some legacy code that works with const char*. Lets say I have a structure which looks like: struct Foo { const char* server; const char* name; }; ...
Irresolution asked 23/6, 2011 at 15:12

2

Solved

So I need log10 functionality to find the number of characters required to store a given integer. But I'd like to get it at compile time to determine the length of char arrays statically based on t...
Whimsey asked 1/10, 2018 at 12:40

3

Solved

I want to convert a __int64 variable into a CString. The code is exactly this __int64 i64TotalGB; CString totalSpace; i64TotalGB = 150; printf("disk space: %I64d GB\n", i64TotalGB); totalSpace.Fo...
Comeuppance asked 25/9, 2018 at 9:28

12

I want to convert a CString into a char[]. Some body tell me how to do this? My code is like this : CString strCamIP1 = _T(""); char g_acCameraip[16][17]; strCamIP1 = theApp.GetProfileString(strS...
Tansy asked 14/5, 2012 at 6:43

8

Solved

Doing this in C++ char* cool = "cool"; compiles fine, but gives me a warning: deprecated conversion from string constant to char*. I would never willfully use a C-style string over std::st...
Lyontine asked 25/7, 2016 at 17:37

1

Solved

I have a FFI signature I need to implement: pub unsafe extern fn f(header_size: u32, header_ptr: *mut u8) -> i32; A FFI caller is expected to provide a buffer header_ptr and the size of that ...
Kommunarsk asked 13/7, 2018 at 8:20

3

Solved

As I understand it, the following code works like so: char* cptr = "Hello World"; "Hello World" lives in the .rodata section of the program's memory. The string literal "Hello World" returns a p...
Donelladonelle asked 19/6, 2018 at 22:59

2

Solved

Say I have something like this extern "C" void make_foo (char** tgt) { *tgt = (char*) malloc(4*sizeof(char)); strncpy(*tgt, "foo", 4); } int main() { char* foo; make_foo(&foo); std::stri...
Vacuva asked 3/6, 2018 at 12:23

3

Solved

Say I have the following: char* string = "Hello, how are you?"; Is it possible to print out only the last 5 bytes of this string? What about the first 5 bytes only? Is there some variation of pr...
Habit asked 15/10, 2011 at 21:40

© 2022 - 2024 — McMap. All rights reserved.