A string in the programming language C is represented as a sequence of characters followed by a null terminator (represented as \0).
Questions tagged [c-strings]
2715 questions
0
votes
3 answers
C char array pointer confusion
I have written following c code:
#include
#include
void func1(char *arr){
printf("%d\n",arr[0]);
printf("%d\n",arr[1]);
return;
}
int main () {
char a[6] = "hello";
printf("%p\n",a);
printf("%p\n",&a);
…

kake
- 25
- 2
0
votes
4 answers
Why does sscanf changing the value of original char array?
I'm not understand how sscanf works.
#include
#include
int main(void)
{
char s[100] = "testtes te asdf newlinetest";
char parm1[10];
char parm2[4];
char parm3[256];
char parm4[10];
printf("BEFORE:…

squinky
- 13
- 4
0
votes
3 answers
Trying to compare a string to a a value with tertiary/conditional operator and it doesn't work
just learning C++ here.
#include
#include
int main()
{
char name[1000];
std::cout << "What is your name?\n";
std::cin.get(name, 50);
name == "Shah Bhuiyan" ? std::cout << "Okay, it's you\n" : std::cout<< "Who…

Shah Jacob
- 137
- 1
- 9
0
votes
1 answer
Strange behavior using CString in swscanf directly
I have one problem with CString and STL's set.
It looks a bit strange to use CString and STL together, but I tried to be curious.
My code is below:
#include "stdafx.h"
#include
#include
#include
using namespace std;
int…

secuman
- 539
- 4
- 12
0
votes
2 answers
C char pointer bug when being able to be in a conditional statement
I am currently trying to manipulate a char pointer variable using strtok. Then using that in a conditional statement to append to an array depending on the current pointers content.
#include
#include
#include
#define…

KeenEm
- 27
- 4
0
votes
2 answers
Character string output when I exceeds the limit
Here I'm using two string
char str[5], rev[5];
Initially I was trying to performe reverse of a string and it was successful.
While I'm printing the characters of rev string I mistakenly exceed the limit of string, but still string rev printing the…

Nagraju Kasarla
- 37
- 6
0
votes
1 answer
Does CPath perform reference counting?
I was wondering whether ATL's CPath behaves like the underlying CString, in that an assignment will result in a ref count rather than a deep copy. I don't see anything in the docs about it, and I'm not sure how to test it. Here's some source that…
user15284017
0
votes
1 answer
Convert string to uppercase with "for" cycle
I am working on a code in C that, based on a 26-character key input by the user in command line (ex: BCDEFGHIJKLMNOPQRSTUVWXYZA), encrypts a source message (plaintext) to an encrypted message (ciphertext) by replacing each letter of the source with…

Andrea De Arcangelis
- 23
- 2
0
votes
1 answer
Why is the array (sentence) printing 38 elements when it only have space for 30?
#include
#include
#include
#include
using namespace std;
int main() {
//initialising the char array and vector
char sentence[30] = {};
vector words{"The", "only", "thing", "to", "fear", "is",…

Charles Simmons
- 5
- 2
0
votes
2 answers
Is it safe to use CString::GetString() with CWnd::SendMessage()?
I have this code:
GetParent()->SendMessage(UWM_DELETE_NAME_HISTORY_MSG, (WPARAM)strName.GetBufferSetLength(_MAX_PATH));
strName.ReleaseBuffer();
Is it safe for me to change it like this:
GetParent()->SendMessage(UWM_DELETE_NAME_HISTORY_MSG,…

Andrew Truckle
- 17,769
- 16
- 66
- 164
0
votes
1 answer
CamelCase to snake_case in C without tolower
I want to write a function that converts CamelCase to snake_case without using tolower.
Example: helloWorld -> hello_world
This is what I have so far, but the output is wrong because I overwrite a character in the string here: string[i-1] = '_';.
I…
user16878246
0
votes
3 answers
How can I fix a string that creates some random characters?
The problem is that when I try to reverse a word, there are some words that prints out with unspecified and random characters. I tried to change the string size and the results change (some words make up random characters and some no)
#include…

reshi
- 1
0
votes
2 answers
How to move uint32_t number to char[]?
I have to copy uint32_t number into the middle of the char[] buffer.
The situation is like this:
char buf[100];
uint8_t pos = 52; // position in buffer to which I want to copy my uint32_t number
uint32_t seconds = 23456; // the actual number
I…

yeuop
- 159
- 1
- 9
0
votes
0 answers
Implementing string to int function in c
I am trying to implement a function as stated in the title. I think I am very close to solution but a problem.
input: 51% are admitted.
output: x:51 (null)
but output should have been:
s:% are admitted.
My try is here:
#include…

akoluacik
- 33
- 5
0
votes
1 answer
Finding substrings in c(Question 8.16 from C how to program)
I am trying to implement the question 8.16 from the C How to program. The question is below:
(Searching for Substrings) Write a program that inputs a line of text and a search string from the keyboard. Using function strstr, locate the first…

akoluacik
- 33
- 5