printf

cuda 11 kernel doesn't run

匆匆过客 提交于 2021-02-05 09:09:23
问题 here is a demo.cu aiming to printf from the GPU device: #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> __global__ void hello_cuda() { printf("hello from GPU\n"); } int main() { printf("hello from CPU\n"); hello_cuda <<<1, 1>>> (); cudaDeviceSynchronize(); cudaDeviceReset(); printf("bye bye from CPU\n"); return 0; } it compiles and runs: $ nvcc demo.cu $ ./a.out that's the output that I get: hello from CPU bye bye from CPU Q: why there is no printing result

Any other way to print on the screen instead of printf() and fprintf() in C?

限于喜欢 提交于 2021-02-04 21:42:32
问题 I'm programming with gcc in CentOS 5.5 and the most of time I use printf() and fprintf() to print on terminal, but in some websites I've seen that some people use write() . I want to know if there's other ways to print on terminal. Thanks. 回答1: There are some major differences between these functions. The standard library provides some functions to output to stdout : printf , puts , putchar etc. And some functions to output to a stream, you can specify the stream to stdout : fprintf , fputs ,

Any other way to print on the screen instead of printf() and fprintf() in C?

寵の児 提交于 2021-02-04 21:40:56
问题 I'm programming with gcc in CentOS 5.5 and the most of time I use printf() and fprintf() to print on terminal, but in some websites I've seen that some people use write() . I want to know if there's other ways to print on terminal. Thanks. 回答1: There are some major differences between these functions. The standard library provides some functions to output to stdout : printf , puts , putchar etc. And some functions to output to a stream, you can specify the stream to stdout : fprintf , fputs ,

C++ mixing printf and cout [duplicate]

£可爱£侵袭症+ 提交于 2021-02-04 19:45:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: mixing cout and printf for faster output I'm using Microsoft Visual Studio 6.0. The following program, #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { printf("a"); printf("b"); printf("c"); return 0; } produces "abc". While the following program, #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { printf("a"); cout<<"b"; printf("c"); return 0; } produces "acb

printf format for 1 byte signed number

[亡魂溺海] 提交于 2021-02-04 15:11:32
问题 Assuming the following: sizeof(char) = 1 sizeof(short) = 2 sizeof(int) = 4 sizeof(long) = 8 The printf format for a 2 byte signed number is %hd , for a 4 byte signed number is %d , for an 8 byte signed number is %ld , but what is the correct format for a 1 byte signed number? 回答1: what is the correct format for a 1 byte signed number? %hh and the integer conversion specifier of your choice (for example, %02hhX . See the C11 standard, §7.21.6.1p5: hh Specifies that a following d , i , o , u ,

printf format for 1 byte signed number

喜你入骨 提交于 2021-02-04 15:10:13
问题 Assuming the following: sizeof(char) = 1 sizeof(short) = 2 sizeof(int) = 4 sizeof(long) = 8 The printf format for a 2 byte signed number is %hd , for a 4 byte signed number is %d , for an 8 byte signed number is %ld , but what is the correct format for a 1 byte signed number? 回答1: what is the correct format for a 1 byte signed number? %hh and the integer conversion specifier of your choice (for example, %02hhX . See the C11 standard, §7.21.6.1p5: hh Specifies that a following d , i , o , u ,

Calling sprintf in x64 assembly

老子叫甜甜 提交于 2021-01-29 19:18:22
问题 It seems that I can't call sprintf() correctly in assembly. When I try to dprintf() my buffer that should now be formatted, all I get is: (null) and a segmentation fault. When running lldb with my program, strlen() is the reason of the fail as it can't find a \0 in my buffer. Here's my code: mov rdi, buff mov rsi, 0 mov rdx, 17 call memset lea rsi, [rel n_head] mov rdx, rax call sprintf mov rdx, rdi lea rsi, [rel fmt] mov rdi, 1 call dprintf ... section .data n_head: db "Low battery: %d%%", 0

C printing extremely weird values with printf

▼魔方 西西 提交于 2021-01-29 12:32:20
问题 I am rewriting this post because I managed to figure out the problem. The problem with my extremely broken output was due to an improper dynamic memory allocation. Basically I needed to allocate memory for an array of pointers that pointed to structs, but the array itself was nested inside of another struct and the nesting confused me slightly and I ended up over complicating it. So I had a struct named Catalog, that my array was in and that array pointed to another struct named Books. When I

default argument promotions and relevance of “%c” in printf

℡╲_俬逩灬. 提交于 2021-01-29 02:25:36
问题 Here's what libc has to say about variadic functions: Since the prototype doesn’t specify types for optional arguments, in a call to a variadic function the default argument promotions are performed on the optional argument values. This means the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int, as appropriate; and that objects of type float are promoted to type double. So, if the caller passes a char as an optional argument, it is promoted

Why does my code keep printing twice? I don't understand the problem [duplicate]

那年仲夏 提交于 2021-01-28 21:13:13
问题 This question already has answers here : How do you allow spaces to be entered using scanf? (11 answers) Closed last year . #include <stdio.h> #define MAX_STRING_LENGTH 1024 int main(){ char input_name_string[MAX_STRING_LENGTH+1],motive_string[MAX_STRING_LENGTH+1]; printf("What is your name?\n"); scanf("%1024s",input_name_string); printf("your name is %s \n", input_name_string); printf("What is your motive?\n"); scanf(" %1024s",motive_string); printf("your motive is %s \n", motive_string);