When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
83 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
is there a %02X that does no padding?
%X
right i think the problem isnt that then lmao
i dont think my scanf is reading the next two characters after the three
and only reads the one
but it works in line 2,3 and 6?
so im confused
also commented the code
what are you trying to do
what format is the input
and what format do you want to convert it to
so say i have like
some characters
like 23fdb
all those are only once so just print as normal
but say 2 is repeated 3 times
it will always have a hexademical after it
222063fdb
for example
so 17___05
should turn into _____
so its a form of run length encoding ?
yes
!f
is there a %02X that does no padding?
`
void expand() {
// Setup
char character, last;
int count;
// While there is no break condition
while (1) {
// Gets the character in the stream
character = (char)getchar();
// Checks if 3 characters are the same to start reading hexadecimal value
if (character == (last = (char)getchar()) && character == (char)getchar()) {
// reads the input as a hexadecimal format, stores it in count
scanf("%X", &count);
// Prints the character for count times by iteration
for (int i = 0; i < count; i++) {
// Prints character
putchar(character);
}
} else {
// Prints character if under 3
putchar(character);
if (last != '\xff') {
putchar(last);
}
}
if (character == '\xff')
break;
}
}
`
this is my code, and it works only in some places as shown in the images. For context this is uncompressing text by reading 3 values then reads the two hexadecimal values after. any help would be appreciated, thank you.
!f
void expand() {
// Setup
char character, last;
int count;
// While there is no break condition
while (1) {
// Gets the character in the stream
character = (char)getchar();
// Checks if 3 characters are the same to start reading hexadecimal value
if (character == (last = (char)getchar()) && character == (char)getchar()) {
// reads the input as a hexadecimal format, stores it in count
scanf("%X", &count);
// Prints the character for count times by iteration
for (int i = 0; i < count; i++) {
// Prints character
putchar(character);
}
} else {
// Prints character if under 3
putchar(character);
if (last != '\xff') {
putchar(last);
}
}
if (character == '\xff')
break;
}
}
thats much nicer to look at i didnt know i could do that lmao
!code
```c
int main() {}
```
int main() {}
do you have a specification of the format ?
how to read it
no
i dont need to do stream input if i dont want to but he said it needs to be efficient
i have working code for a compression to that format but cant get this reverse function to work for some reason
when do you know a character needs to be repeated n times ?
when its repeated 3 times
im not quite sure what counts as a newline but
\n or Return
no newlines no
it keeps reading until no characters are given
though im not sure if what might be messing it up is
i have the firstline as either C or E
then it calls the function
if (character == (last = (char)getchar()) && character == (char)getchar()) {
that looks quite sus to me
you could like
char c0 = getchar();
char c1 = getchar();
if (c0 == c1) {
char c2 = getchar();
if (c1 == c2) {
parse hex
print c0 n times
} else {
ungetc(c2, stdin);
ungetc(c1, stdin);
}
} else {
ungetc(c1, stdin);
}
print c0
ungetc puts the read character back
it definitely reads it now
when does it tell you to use a newline ?
thats why i was requesting one
i see
then yes i think so
wait got confused mid way lmao
there bit easier on eyes i thinks
OK FIXED IT
YUPE
@latent hazel thank you a lot :3
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
yeah this is completely fcked
oh it's solved already. nevermind 🙂
:3
haha im sorry i thought i could get it in one line but overcomplicated it for myself a bit
the main problem is that you're comparing character with the result of a conditional, i.e. 0 or 1
right i see thats why it always failed
thank you for pointing that out
it helps as im vvv new to c
no problem, glad i could help even when i thought this was solved
actually there still is an issue i thinks
not sure if youre still around
at the end of my output i dont think it breaks properly
not quite sure what would be causing it
since it checks if c0 == '\xff' it breaks