34 questions
1
vote
1
answer
85
views
Printf command stops working when DEBUG trap is active?
When I set a DEBUG trap in Bash like this:
set -o functrace
trap 'echo "# $BASH_COMMAND" >&2' DEBUG
Suddenly, this function stopped working:
getBase() {
local base="$1"
...
0
votes
0
answers
76
views
Why I can't use printf() with variable 'i' as argument
`
void DisplayFood(int*NumOfFood,int*Rno,char *Names[],int*Price,int*Quantity,char*mfg[],char*exp[]) {
int i =0;
for(i=0;i<*NumOfFood;i++) {
printf("\n%-20d",Rno[i]);
...
0
votes
0
answers
216
views
Sprintf function converting int to a single char instead of a string
I'm trying to convert the unsigned long integer converted_binary, which contains 10000000000 to a string, but sprintf converts it to a single character 1 instead.
I am able to know this through the ...
1
vote
2
answers
293
views
Inject string to const char* message in custom logger printf-style function
I have a debugger class which implements a printf() c style method.
It looks like this:
#define NO_DEBUG 0
#define NO_PREFIX 1
#define DEBUG_INFO 2
#define DEBUG_SUCCESS 3
#define DEBUG_WARN 4
#define ...
0
votes
1
answer
102
views
Trouble understanding statement order in Chisel
Here is a simple module containing a down counter:
import chisel3.util.{Valid, DeqIO}
class Input(WIDTH : Int) extends Bundle {
val x = UInt(WIDTH.W)
}
class Output(WIDTH : Int) extends Bundle {
...
-2
votes
1
answer
140
views
how can we see the .exe printf message [closed]
I have an question about the .exe log. I am using raspberry pi 4 module with Debian OS where I am running my c-program from the .service base auto-start .exe process. Which is running well So whenever ...
1
vote
1
answer
134
views
C struct glitch? (I am new to programing in C)
I am learning how to create struct's and I am stuck on a program I made. Everything works fine until I try to input "2". When the program prints the symbol it's supposed to be "He" ...
0
votes
0
answers
87
views
Function doesn't return expected value and printf doesn't return any value
Hi I am new to C but not to programming(Only have experience in high-level languages like Python and JS).
In my CS assignment I have to implement a function that decodes an encrypted string.(The ...
0
votes
1
answer
73
views
Why removing a printf function messes up with my code? CS50 pset1 cash greedy challenge
I finished the challenge and my first C code worked apparently well, returning each time the correct minimum number of coins needed for change. Then when I tried to "clean it up" a bit and remove a ...
0
votes
1
answer
1k
views
printf for a C (not C++) program while using Qt Creator (not using any kinf of Qt framework)
Please note this is not C++ code and I'm not developing a Qt app.
I mostly develop embedded code and someone has knocked up a neat LCD emulator so we can write quite a lot of the code independent of ...
0
votes
1
answer
535
views
printf not print string after \n (Compiler GCC)
See my code
char t[]= "{\n abcdeffgjejgjergnjkengkknkn \n";
printf("%s",t);
char t1[]= "{ abcdeffgjejgjergnjkengkknkn \n aaffdefa";
printf("%s",t1);
Actual Output:
{
{ abcdeffgjejgjergnjkengkknkn
...
0
votes
3
answers
2k
views
Variable declaration inside curly braces
Why does the following code produce an error? I don't understand why the curly braces are making a difference.
#include<stdio.h>
int main(void)
{
{
int a=3;
}
{
...
1
vote
3
answers
775
views
For loop with printf as arguments
I can't understand why the following code outputs 10.
What I understand is that !printf("0") means !0, which is TRUE. So why doesn't the code print "Sachin"
#include <stdio.h>
int main() {
...
0
votes
4
answers
89
views
Program compiles but then gives error Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double?
My program is supposed to print out a table like this:
Time Fraction Since Midnight
12:00 AM 0.0000
1:00 AM 0.0417
2:00 AM 0.0833
3:00 AM 0....
-1
votes
1
answer
1k
views
Ignoring special characters while preserving formatting with MATLAB's fprintf function
I have a string array in a matlab script called "dataString" that was copied into MATLAB from an html document using fileread(). I then cut out the part I wanted and stored that in dataString.
TEXT =...
1
vote
3
answers
137
views
Ubuntu (14 & 16) Bash errors with printf loops from input containing lowercase "n" characters
I have some bash scripts I have been running on Ubuntu 14.04 and 16.04 for well over a year now. Some recent Ubuntu update has broken bash and I cannot figure out how to sort this out.
Example:
#!/...
0
votes
2
answers
1k
views
printf crashes after successful printing
Language is C. I have an array of char* types (char *array[] / char** array) as function argument, and I want to print them all to separate lines like this:
while (*array) {
printf("%s\n", ...
2
votes
4
answers
29k
views
How to print a parenthesis in C with printf?
I am trying to print a parenthesis using:
printf("\)");
However, it is giving me the following warning:
warning: unknown escape sequence '\)'
I can't seem to find a clear explanation anywhere on how ...
2
votes
1
answer
8k
views
How to pass application printf messages to /var/log/messages
I want to pass application printf log messages to the /var/log/messages.
Because kernel debug messages can be visible to /var/log/messages.But i am not getting how to pass application printf log ...
31
votes
2
answers
11k
views
Best way to emulate __typeof__ for msvc or alternative workaround?
I have some code
#define DEBUG_PRINT(x,...) \
do \
{\
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wunused-value\"") \
__typeof__((0,x)) _x = x; ...
-1
votes
1
answer
464
views
Undefined reference in Kdevelop
I have main.cpp, linking test function from io.c
#include <iostream>
#include "io.h"
int main(int argc, char **argv) {
test();
return 0;
}
io.c:
#include <stdio.h>
#include "io....
-3
votes
2
answers
132
views
printf not working and other troubles
I finally got my change program to print out some numbers instead of throwing a floating point exception. However, now it is slightly off. Instead of giving 2 quarters, 1 dime, 1 nickel, and 2 pennies,...
0
votes
1
answer
760
views
printf debugging to trace a function
I'm trying to port software to a microcontroller (so I can't step through the code with e.g. gdb) and it crashes unpleasantly.
To identify the reason for this, I want to insert a printf() before every ...
1
vote
4
answers
2k
views
How to extract context informationm the equivalent of __LINE__, __FILE__,etc., in VBSCRIPT
I'd like to know how to get the line number of a line in vbscript programmaticly either at the point of the code like __LINE__ or more ideally a way to get the line number of where the current ...
0
votes
1
answer
583
views
python - is there no better way to get the expression in a debug function
in c code I frequently use printf debugging macros like
#define DPRINT_INT(i) fprintf(stderr,"%s has the value %i at line %i", #i,i, __LINE__)
and then i can do things like
DPRINT_INT(height)
where ...
8
votes
3
answers
1k
views
Type overloading macro
I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc ...
6
votes
2
answers
8k
views
Setting CFLAGS for pr_debug and printk
I am trying to understand a Linux kernel module and would like to see the output of pr_debug and printk. I am using GNU Make.
I understand that to get pr_debug messages, we have to use DDEBUG.
...
62
votes
6
answers
12k
views
How to "debug" Haskell with printfs?
coming from the Ocaml community, I'm trying to learn a bit of Haskell. The transition goes quite well but I'm a bit confused with debugging. I used to put (lots of) "printf" in my ocaml code, to ...
8
votes
11
answers
3k
views
Educational example to show that sometimes printf as debugging may hide a bug
I remember when I was in some course of C programming, a teacher once suggested that I use printf to watch the execution of a program that I was trying to debug. This program had a segmentation fault ...
45
votes
6
answers
22k
views
What is "p" in Ruby?
I'm sure it's a silly question to those who know, but I can't find an explanation of what it does or what it is.
CSV.open('data.csv', 'r') do |row|
p row
end
What does "p row" do?
-1
votes
2
answers
139
views
Why would a log statement change the output of a program?
I was once asked during an interview the following question, and I've still never been quite clear on the answer. I was wondering if anyone knew where I could learn more, googling hasn't been much ...
3
votes
7
answers
4k
views
C Programming: seg faults, printf, and related quirks [duplicate]
As many young programmers do, I learned the usefulness of inserting numerous print-to-console statements of "here1," "here2," and so on at different points in code to figure out when my programs are ...
330
votes
11
answers
249k
views
How do I dump an object's fields to the console?
When I'm running a simple Ruby script, what's the easiest way to dump an object's fields to the console?
I'm looking for something similar to PHP's print_r() that will work with arrays as well.
49
votes
19
answers
31k
views
What is the proper name for doing debugging by adding 'print' statements [closed]
There are many ways of doing debugging, using a debugger is one, but the simple one for the humble, lazy, programmer is to just add a bunch of print statements to your code.
i.e.
def foo(x):
...