My loop duplicates the last char... (Language C)(feof)(char by char) - feof

Yo guys,
I'm trying to read a text file:
while(!feof(fp)){
fscanf(fp, "%c", &c);
printf("%c", c);
}
But... the output always duplicate the last char, I dont know why... :/
Any idea?

I've wondered that too, finally I found an answer!
I could not explain it any better, so check out the link

Related

How can I get an int next to a word using scanf?

How can I extract an int contained in a string like att249 or berlin32 using sscanf ?
I tried
"%s%d"
Which doesn't work because the %s scan doesn't stop on the 2
After asking on the OCaml discord, I got the answer on how to achieve this :
"%[^0-9]%d"
Which works well because %[^0-9] scan until it encounters a digit.
Being a complete beginner in scanf, I don't know if it's the best way to achieve it though.

App is getting in infinite loop when using regular expression in loop

Something strange is happening. I'm using regular expressions that I'm 100% sure are working, but when putting them into the loop, it causes the app to get in freeze state, printing out values tens of thousands of times. Any possible suggestions?
My code :
UPDATE: IT WAS A BIG MISTAKE
As we discussed it in comments.
You have to change the incremental statement from i++ to n++
I hope that helped you.

Can not find the behaviour of a macro

On the web i have found a nice LCD library for use with a PIC16F877A. I worked with a sample but I need to change the output ports of the PIC.
The lib indicates a possibility but that does not work. So no other way then trying to understand the lib.
#define LCD_DATA_TRIS D
#define LCD_DATA_POS 0
//LCD_DATA_TRIS &=(~(0x0F<<LCD_DATA_POS));
TRISD &=(~0x0F);
The above brings me to a reduced and working macro but I want to eliminate it completely. Somehow that does not succeed. It has to do with the ~. I can not find the working of it.
Help appreciated
In the meanwhile I have found the answer.
TRISD &= 0xF0 since the ~ reverses all the bits in the hex value.

How do I get substring to work in matlab?

I apologize if this is a newb question, but I have read the documentation here and it says nothing about having to input any command before using substring.
However, when I try to call it as follows:
substring('hello world', 2)
It gives me the error
??? Undefined function or method 'substring' for input arguments of type 'char'.
What is the correct way to invoke this substring?
Not to detract from the OP's answer, which actually more directly adresses the question you ask, but assuming all you want to do is extract a certain number of characters from a string, MATLAB's indexing is all you need:
myString = 'Hello, world!';
mySubstring = myString(3:end)
mySubstring =
llo, world!
substring is not a MATLAB function at all, at least in MATLAB proper. There IS a substring JAVA function, but I have no idea if that is what you are asking.
>> which substring
substring is a Java method % java.lang.String method
The above also tells you what you will need to do. Look here. (Google is your friend. Of course, you could as easily have done exactly what I just did, and gotten this answer far more quickly.)
You may also be talking about some custom code, written by some colleague of yours. In that case, talk to your friend. Very often I hear about tools that were written by someone, then left around as legacy code, unsupported. Eventually, it just disappears due to path issues when new versions of MATLAB are installed.
You might actually want strsplit. This will parse char data by a given or default delimiter and return a cell array of the pieces.

Comparing Strings Objective C

When I use == to compare the strings it works on all but some strings that have a space added... (added with [NSString stringWithFormat:#"%# %#",self.title,collectionName])
But when I compare with isEqualToString, it returns True/YES every time. The comparison in the image goes into the condition and hits the return... Should be impossible for this to hit line 640, but it does.
Can anyone explain this?
There is a ";" after the ")" on line 637 that why it always went into the condition... damn I suck... seems like that would throw an error somehow
If you use the LLVM compiler in Debug project setting, (not quite stable enough for release yet I think), you'll get warnings about issues like the one you had.
In your case it would issue a warning than an "if" statement had an empty body.
Used in conjunction with turning on the static analyzer for every build, you can catch a ton of problems early, especially the stupid ones that are hard to debug because they are so stupid they are easy to overlook (and here I am not criticizing you, as I have made the same mistake countless times!)