October 21, 2024
Chicago 12, Melborne City, USA

C++

C++ is a general-purpose programming language. Use this tag for questions about/utilizing C++. Do not also tag questions with [c] unless

C++

C programming weird behaviour of “\t” (newtab)

so I’ve come across a weird scenario. When running this code: #include<stdio.h> main(){ printf("Fahrenheit\tCelsius\n"); printf("Celsius\tFahrenheit\n"); } it will show Fahrenheit Celsius Celsius Fahrenheit Can somebody explain why is the \t behaving like this? Instead of: Celsius Fahrenheit it should show: Celsius Fahrenheit You need to sign in to view this answers

Read More
C++

Strict Aliasing and Unions in C

Consider the following C program (which is based on an example from this article): #include <stdio.h> short g(int *p, short *q) { short z = *q; *p = 10; return z; } int main(void) { union int_or_short { int x; short y; } u = { .y = 3 }; int *p = &u.x; short

Read More
C++

C Program ending after printf()

I’m making a mini system for personal educational purposes, but I’m not having success in this part. After executing a printf(), the program simply returns: Process returned -1073741819 (0xC0000005) const char* nomePastaContas = "contas"; char *ibanPessoal; char *passwordPessoal; void loginMenu(){ system("cls"); printf("\n\n IBAN: "); scanf("%s", &ibanPessoal); printf("\n\n Password: "); scanf("%s", &passwordPessoal); printf("Debug"); verificarConta(ibanPessoal, passwordPessoal); }

Read More
C++

Generic QuickSort implementation struggles with a lot of strings

Ok basically i made this quicksort implementation in C for uni that is supposed to be able to recieve any type of array and sort it. For a stress test I was provided a records.csv file with 20mil lines structured like this: <id [int]>,<field1 [string]>,<field2 [int]>,field3 [float]> My algorithm has to sort the file lines

Read More
C++

Is this an error in the documentation of TransparentBlt()?

Microsoft’s documentation of the GDI function TransparentBlt() states: The TransparentBlt function supports all formats of source bitmaps. However, for 32 bpp bitmaps, it just copies the alpha value over. Is this an error? The code below contradicts that documentation by demonstrating that TransparentBlt() zeroes out the Alpha channel value for the non-transparent pixel, and does

Read More
C++

PAM pam_prompt function returning conversation failed error if called from pam_sm_open_session

I am trying to create a custom PAM module, where I check amount of sessions a user has and if the user has the right permissions offer him to kill a session, I am trying to give the user a prompt with a list of sessions and offer to kill one of them. But if

Read More
C++

Check if uint8_t array contains string

In C language I have a uint8_t array and, after some logic, I need to cast to string and check if contains some substring like this: uint8_t data[8] = {0xcb,0xe2,0x3d,0x96,0x55,0xfc,0xcd,0x43}; /// some logic if(strstr((const char *)data, "000") != NULL){ } Is if statement correct? it seems to return always true. You need to sign in

Read More
C++

Problem to stop a function and restart it at the same location

I have a problem with my Arduino code. I’m building a small traffic-light system which I need for my base project. Now I have a problem, I can’t get the program to stop when the button is clicked twice and to continue running in the same place when it is clicked again. #define one_Red 3

Read More
C++

voltage sensor using a voltage divider

I would like to ask about a voltage sensor using a voltage divider. I have a circuit as shown below, and I want to measure the voltage entering my circuit using the code below. However, I am uncertain because I am still a beginner and I need your guidance. What is lacking in this code,

Read More
C++

How to write a piece of source code that can be executed as both C and Python, outputting 'Hello World'

I’m trying to write a piece of source code that is compatible with both C and Python compilers/interpreters, outputting "Hello World" in stdout. Here are two of my tries: #if __STDC__ #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } #else print("Hello, World!") exit() #endif """" #include <stdio.h> int main() { printf("Hello, World!\n"); return

Read More