Go to advanced search

by lianergoist
Sat Aug 11, 2018 9:21 am
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

Re: How do I debug stdin?

Perhaps now is the time to download the source of glibc and look at the code for fflush? No need for that. A quick google search show tthe behavior of flushing stdin is undefined. See https://www.geeksforgeeks.org/clearing-the-input-buffer-in-cc/ I tend to just assume this stuff works, its been aro...
by lianergoist
Sat Aug 11, 2018 6:44 am
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

Re: How do I debug stdin?

Perhaps there is simply no stuff in the buffer waiting to be read. In which case fflush() would do nothing. Perhaps? But isn't it clear there *is* something in the buffer "('y\n"), both before and after fflush? I would expect both _IO_read_end and (for sure) _IO_read_ptr to point to same address as...
by lianergoist
Sat Aug 11, 2018 6:06 am
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

Re: How do I debug stdin?

So try 'print *stdin' and see what that gets you. Well, I *did* know that, so this is a little embarrassing... :roll: Well, I leaned something today. fflush has no effect on stdin... (gdb) next Search another word? (y/n) 36 selected = fgetc(stdin); (gdb) next y 37 } while (selected == '\n'); (gdb) ...
by lianergoist
Fri Aug 10, 2018 8:57 pm
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

Re: How do I debug stdin?

In psuedo-code: loop_start: read character from stdin if character == "\n" go to loop_start "\n" is the escape sequence that matches the LF character (0x0a ascii) Well, I know that much. I think I am a little confused about why it should do what my book said it was supposed to do (jump over the LF ...
by lianergoist
Fri Aug 10, 2018 7:25 pm
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

Re: How do I debug stdin?

jahboater wrote:
Fri Aug 10, 2018 4:49 pm
I suspect mixing fgetc and getline is confusing things.
Does this do what you want ?
Thank you for helping me. Yes, it works. It's smart only to read the first char of the string.

I will be back after some testing.... :)
by lianergoist
Fri Aug 10, 2018 4:14 pm
Forum: C/C++
Topic: How do I debug stdin?
Replies: 12
Views: 1286

How do I debug stdin?

I hope this kind of question is on-topic here. Else, plese let me know. I have a problem with the LF character. I have made a little demo to show the problem: #include <stdlib.h> #include <stdio.h> void search_word() { char *tmp_string; size_t len=50; tmp_string = (char *) malloc(len * sizeof(char)+...
by lianergoist
Sat Jul 28, 2018 1:15 pm
Forum: C/C++
Topic: What's wrong with wprintf?
Replies: 2
Views: 452

Re: What's wrong with wprintf?

joan wrote:
Sat Jul 28, 2018 12:41 pm
Use fwide(stdout, 1) to set wide char mode.
Thank you very much. There's always something new to learn, I guess. Btw, there is also a good explanation here: https://www.gnu.org/software/libc/manua ... s-and-I18N
by lianergoist
Sat Jul 28, 2018 10:13 am
Forum: C/C++
Topic: What's wrong with wprintf?
Replies: 2
Views: 452

What's wrong with wprintf?

I have a little problem with wprintf - it doesn't work at all! :-) No, it's true. #include <stdio.h> #include <stdlib.h> #include <wchar.h> int main () { wchar_t wstring[50]; printf("Word to delete: "); wscanf(L"%50S", &wstring); wprintf(L"From wprintf: %S\n", wstring); printf("From printf: %ls\n", ...
by lianergoist
Sat Jul 28, 2018 8:48 am
Forum: C/C++
Topic: GCC 8.2 released
Replies: 7
Views: 2905

Re: GCC 8.2 released

Also +1 from me! Maybe this is a stupid question, but why do we need the extra options to configure? Isn't it supposed to auto-detect that? Sure, things like --enable-languages=c,c++ makes sense, but the rest of it looks like it could/would/should be auto-detected. I ask because I plan to install gd...
by lianergoist
Tue Jul 10, 2018 7:53 am
Forum: C/C++
Topic: [Solved] Reading from stdin
Replies: 7
Views: 904

Re: Reading from stdin

Here are the imoprtant bits of the man page for fgetc (run "man fgetc" to see the full page). Thanks! Well, the problem is not that I don't read the documentation, the problem is I don't fully understand it. Most of the code I have seen use a char to hold the value returned from fgetc(): I have act...
by lianergoist
Tue Jul 10, 2018 7:42 am
Forum: C/C++
Topic: [Solved] Reading from stdin
Replies: 7
Views: 904

Re: Reading from stdin

You are storing the value returned by fgetc() into a char but fgetc() doesn't return a char , it returns an int , this is because EOF cannot fit in a char ( char is unsigned on ARM so can hold values from 0 to 255, EOF is -1), -1 when stored in a char becomes 255 so your test for EOF ends up being ...
by lianergoist
Mon Jul 09, 2018 9:53 pm
Forum: C/C++
Topic: [Solved] Reading from stdin
Replies: 7
Views: 904

[Solved] Reading from stdin

How do I find the end of a file when it is redirected to stdin and I read one character at a time? I have made a little test that show a problem: [email protected]:~/c/ooo $ cat test.txt this is a test [email protected]:~/c/ooo $ cat test2.c #include <stdio.h> #include <stdlib.h> int main(int argc, char *...
by lianergoist
Mon Jul 09, 2018 7:10 pm
Forum: C/C++
Topic: Problem writing to /dev/tty
Replies: 4
Views: 799

Re: Problem writing to /dev/tty

joan wrote:
Mon Jul 09, 2018 5:42 pm
Output is buffered until a newline is seen.
I am just been told to use fflush()... I have spend hours trying to figure out what I was doing wrong, and then the answer is simply fflush()... Well, thank you.
by lianergoist
Mon Jul 09, 2018 5:29 pm
Forum: C/C++
Topic: Problem writing to /dev/tty
Replies: 4
Views: 799

Re: Problem writing to /dev/tty

I've not had a chance to look at you code, but I use this little function:- My subject line may be a little misleading. I can write to both stdout and /dev/tty, but I have some problems with the newline character - or rather lack of newline character. Take a look at the code when you have the time ...
by lianergoist
Mon Jul 09, 2018 4:11 pm
Forum: C/C++
Topic: Problem writing to /dev/tty
Replies: 4
Views: 799

Problem writing to /dev/tty

I have a little problem. I want to let the user redirect output from my program, but I still want to be able to write to write to the screen. The solution to that should be to use stdout to the text that should be redirected and /dev/tty to the text that should be printed on the screen (and not redi...
by lianergoist
Fri Jun 22, 2018 8:10 pm
Forum: C/C++
Topic: [Solved] Segmentation fault and debugging
Replies: 7
Views: 3323

Re: Segmentation fault and debugging

It may not be the only bug, but in test_word_exists the code opens a file, but if "j == pl" is true the function returns without closing the file. See obvious comment in code below. PeterO Bingo! I am sure you just found the problem. And yes, there are other bugs. I found one earlier, but I can't r...
by lianergoist
Fri Jun 22, 2018 3:14 pm
Forum: C/C++
Topic: Looking for good C/C++ resources for PI
Replies: 18
Views: 3704

Re: Looking for good C/C++ resources for PI

If you want a gui for gdb, try 'Nemiver'. I have only used it a few times myself, but it seems to be quite okay. https://wiki.gnome.org/Apps/Nemiver
by lianergoist
Fri Jun 22, 2018 3:05 pm
Forum: C/C++
Topic: [Solved] Segmentation fault and debugging
Replies: 7
Views: 3323

Re: Segmentation fault and debugging

You should compile it with: -O0 -g Then run it in the debugger (gdb). When you get the segfault, type "bt" for back trace - which will show you the line number where the crash occurred. Often thats enough! Thank you for answering. I am afraid it didn't help me much. [email protected]:~/c $ gcc --versi...
by lianergoist
Fri Jun 22, 2018 11:48 am
Forum: C/C++
Topic: [Solved] Segmentation fault and debugging
Replies: 7
Views: 3323

[Solved] Segmentation fault and debugging

I have made a little program that takes a text and compare the words to a list of words, and if some of the words doesn't exist in the list, they will be added to a new file. (four letter words are compared to words in 4.txt, five letter words to 5.txt, etc.) The program sort of works. It is not bea...
by lianergoist
Wed Jun 13, 2018 4:52 am
Forum: C/C++
Topic: wchar functions
Replies: 3
Views: 501

Re: wchar functions

markkuk wrote:
Tue Jun 12, 2018 7:26 pm

Code: Select all

setlocale(LC_ALL, "");

Oh, thank you, man. I have seen someone on the net suggest "setlocale(LC_CTYPE, "en.UTF-8")", but that didn't work. This does! Thanks again!
by lianergoist
Tue Jun 12, 2018 5:16 pm
Forum: C/C++
Topic: wchar functions
Replies: 3
Views: 501

wchar functions

Does somebody here know how to use the wchar functions in C? I have been fighting this all day, and I can't get anything to work. I have read the glibc doc and searched the net, but still stuck... Well, basically I have a list of words, and I want to sort it by length of words. In fact, I want to wr...
by lianergoist
Fri Jun 01, 2018 8:36 am
Forum: Troubleshooting
Topic: Running wget from a script
Replies: 1
Views: 152

Running wget from a script

I download 4 index files with wget from a script. For some unknown reason something - sometimes - goes wrong. I am not sure what it is and why, but I think it has something to do with some time-outs or something. If I run the commands one at a time, I have never problems. But when I run the script, ...
by lianergoist
Fri May 18, 2018 5:28 pm
Forum: Advanced users
Topic: Checking for new files with wget
Replies: 2
Views: 293

Re: Checking for new files with wget

I was going to suggest using --timestamping and --no-if-modified-since but that site seems to not publish a Last-Modified header. I don't suppose they could turn that on, could they? Thank you very much. It's a shame if the site really does not return a Last-Modified header. I have just been readin...
by lianergoist
Fri May 18, 2018 2:51 pm
Forum: Advanced users
Topic: Checking for new files with wget
Replies: 2
Views: 293

Checking for new files with wget

Hi I have set up a BitTorrent server on a raspberry pi zero where I have the NOOBS and raspbian images. To always have the latest images, I have made a little script (for each image) I run every night from a cron job. #!/bin/bash #get list of NOOBS images wget https://downloads.raspberrypi.org/NOOBS...
by lianergoist
Fri May 04, 2018 4:07 pm
Forum: HATs and other add-ons
Topic: Zero4U power consumption
Replies: 4
Views: 801

Zero4U power consumption

I have just bought a Zero4U usb hub. The card works fine, but it use some power. Without devices connected it use almost nothing, but with a mouse or keyboard connected, it use far more beyond what the mouse / keyboard draws. Raspberry Pi Zero + Zero4U without mouse / keyboard (idle) = 0.5W With mou...

Go to advanced search