Time exceeded limit in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Time exceeded limit in c

I tried to run the code but it said time exceeded limit. What do i have to change? a.dat file contain = 0x01 0x02 0x03 0x41 0x42 0x43 0x0D 0x0A 0xFF 0xFE 0xFD 0x01 0x02 0x03 0x80 0x7F 0x0D 0x0A ######### Example1: Input = 01 Output = 2 (Because there are 2 0x01 in the file) Example2: Input = FF Output = 1 (Because there is 1 0xFF in the file) The code: https://code.sololearn.com/cI0ZmcK1wPpb/?ref=app

6th Jun 2022, 12:12 PM
Smokie Raccoon
4 Answers
0
It doesnt work
6th Jun 2022, 12:35 PM
Smokie Raccoon
0
Try while (fscanf(in,"%x",p++) != '\0'){ also since you are returning zero, you main should be the following: int main
8th Jun 2022, 1:44 AM
The Darkness
The Darkness - avatar
- 1
Use 0 instead of EOF, try this : while (fscanf(in,"%x",p++) != 0){ n++; }
6th Jun 2022, 12:29 PM
Jayakrishna 🇮🇳
- 1
fscanf returns zero, if unsuccessful. Otherwise, it returns The input string, if successful. while (fscanf(in , "%x", (p+i)) == 1) { n++; i++; } Should work any of 2. Otherwise it some other error.. edit: Smokie Raccoon can't test here but try open file in read mode only "r" Hope it helps.....
6th Jun 2022, 1:03 PM
Jayakrishna 🇮🇳