Why doesn't this fragment work?
FILE *file;
fopen(argv[1], "r+");
fprintf(file, "\b");
THX
nertos
--
nertos | nertos@o2.pl |
poznan.linux.org.pl |
|
|
0
|
|
|
|
Reply
|
nertos
|
3/10/2005 7:48:19 PM |
|
nertos <my-nick@-------spammmmmm-to-zlo----o2.pl> scribbled the following:
> Why doesn't this fragment work?
> FILE *file;
> fopen(argv[1], "r+");
> fprintf(file, "\b");
You have to assign the return value of fopen() to file.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
|
|
0
|
|
|
|
Reply
|
palaste (2323)
|
3/10/2005 7:49:23 PM
|
|
nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
> Why doesn't this fragment work?
>
> FILE *file;
>
> fopen(argv[1], "r+");
>
> fprintf(file, "\b");
You didn't assign anything to `file'.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x1f6},*p=
b,x,i=24;for(;p+=!*p;*p/=4)switch(x=*p&3)case 0:{return 0;for(p--;i--;i--)case
2:{i++;if(1)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
|
|
0
|
|
|
|
Reply
|
blp (3953)
|
3/10/2005 7:49:52 PM
|
|
"nertos" <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> wrote in message
news:d0q8a2$djn$1@atlantis.news.tpi.pl...
> Why doesn't this fragment work?
>
> FILE *file;
>
> fopen(argv[1], "r+");
>
> fprintf(file, "\b");
>
> THX
> nertos
>
You are not checking if there are enough args, what does argc say? You are
also not checking to see if file is NULL to determine if it has been
successfully opened. For writing a file (with a char like '\b'), I would
suggest using "wb". something like this:
if (argc>0)
{
file = fopen(argv[1], "wb");
if (file)
{
fprintf(file, "\b");
fclose(file);
printf("Successful\n");
}
else
{
printf("Could not open file %s\n", argv[1]);
}
}
else
{
printf("No command line arguements supplied\n");
}
HTH
Allan
|
|
0
|
|
|
|
Reply
|
abruce (27)
|
3/10/2005 7:52:56 PM
|
|
"Ben Pfaff" <blp@cs.stanford.edu> wrote in message
news:877jkfe0wv.fsf@benpfaff.org...
> nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
>
>> Why doesn't this fragment work?
>>
>> FILE *file;
>>
>> fopen(argv[1], "r+");
>>
>> fprintf(file, "\b");
>
> You didn't assign anything to `file'.
I didnt notice that, here was me telling him to check that file was non-null
after fopen() and he didnt even assign it!
Allan
|
|
0
|
|
|
|
Reply
|
abruce (27)
|
3/10/2005 7:56:55 PM
|
|
Allan Bruce wrote:
> "Ben Pfaff" <blp@cs.stanford.edu> wrote in message
>> nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
>>
>>> Why doesn't this fragment work?
>>>
>>> FILE *file;
>>>
>>> fopen(argv[1], "r+");
>>>
>>> fprintf(file, "\b");
>>
>> You didn't assign anything to `file'.
>
> I didnt notice that, here was me telling him to check that file
> was non-null after fopen() and he didnt even assign it!
I suspect nertos is a troll trying to get people to trigger the
Windoze bug of crashing when backspacing at the start of a line.
--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
|
|
0
|
|
|
|
Reply
|
cbfalconer (19183)
|
3/11/2005 5:14:22 AM
|
|
CBFalconer <cbfalconer@yahoo.com> writes:
> Allan Bruce wrote:
>> "Ben Pfaff" <blp@cs.stanford.edu> wrote in message
>>> nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
>>>
>>>> Why doesn't this fragment work?
>>>>
>>>> FILE *file;
>>>>
>>>> fopen(argv[1], "r+");
>>>>
>>>> fprintf(file, "\b");
>>>
>>> You didn't assign anything to `file'.
>>
>> I didnt notice that, here was me telling him to check that file
>> was non-null after fopen() and he didnt even assign it!
>
> I suspect nertos is a troll trying to get people to trigger the
> Windoze bug of crashing when backspacing at the start of a line.
If so, he's an incompetent troll; the program won't write a backspace
character (unless it does so as an unlikely consequence of undefined
behavior). (Conceivably he just didn't test the program because he
doesn't want to crash his own system.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
3/11/2005 9:01:12 AM
|
|
Keith Thompson wrote:
> CBFalconer <cbfalconer@yahoo.com> writes:
>> Allan Bruce wrote:
>>> "Ben Pfaff" <blp@cs.stanford.edu> wrote in message
>>>> nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
>>>>
>>>>> Why doesn't this fragment work?
>>>>>
>>>>> FILE *file;
>>>>>
>>>>> fopen(argv[1], "r+");
>>>>>
>>>>> fprintf(file, "\b");
>>>>
>>>> You didn't assign anything to `file'.
>>>
>>> I didnt notice that, here was me telling him to check that file
>>> was non-null after fopen() and he didnt even assign it!
>>
>> I suspect nertos is a troll trying to get people to trigger the
>> Windoze bug of crashing when backspacing at the start of a line.
>
> If so, he's an incompetent troll; the program won't write a
> backspace character (unless it does so as an unlikely consequence
> of undefined behavior). (Conceivably he just didn't test the
> program because he doesn't want to crash his own system.)
He could be a devious troll, who wants people to correct and run
his snippet. The fact that he never reappears tends to confirm my
suspicion.
--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
|
|
0
|
|
|
|
Reply
|
cbfalconer (19183)
|
3/11/2005 2:01:03 PM
|
|
>
> I suspect nertos is a troll trying to get people to trigger the
> Windoze bug of crashing when backspacing at the start of a line.
>
This must only be for some versions of windows is it not? I have not tried
this code on XP but I am sure I have tried very similar with no problems.
Allan
|
|
0
|
|
|
|
Reply
|
abruce (27)
|
3/11/2005 2:26:44 PM
|
|
On Fri, 11 Mar 2005 14:26:44 -0000, in comp.lang.c , "Allan Bruce"
<abruce@TAKEMEAWAY.csd.abdn.ac.uk> wrote:
>>
>> I suspect nertos is a troll trying to get people to trigger the
>> Windoze bug of crashing when backspacing at the start of a line.
>>
>
>This must only be for some versions of windows is it not? I have not tried
>this code on XP but I am sure I have tried very similar with no problems.
nope, it works on XP too. Its not as trivial as the example posted herewith, and
MS may have finally patched it of course.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
|
|
0
|
|
|
|
Reply
|
markmcintyre (4547)
|
3/11/2005 3:37:10 PM
|
|
nertos schrieb:
> Why doesn't this fragment work?
> FILE *file;
> fopen(argv[1], "r+");
> fprintf(file, "\b");
This depends on compiler and optimisation.
A compiler analyse, that file is not set to any value.
Therefore no storage is assigned.
A variable without storage must be in register.
the not assigned register number may be zero,
and must be stored for the argument list of fprintf.
Hermann
assuming, that compiler should assign initial value NULL
or 0xFFFFFFFF to file.
|
|
0
|
|
|
|
Reply
|
nospam.comp05e3 (1)
|
3/11/2005 6:27:53 PM
|
|
CBFalconer <cbfalconer@yahoo.com> writes:
> Keith Thompson wrote:
>> CBFalconer <cbfalconer@yahoo.com> writes:
>>> Allan Bruce wrote:
>>>> "Ben Pfaff" <blp@cs.stanford.edu> wrote in message
>>>>> nertos <my-nick@-------SPAMMMMMM-to-zlo----o2.pl> writes:
>>>>>
>>>>>> Why doesn't this fragment work?
>>>>>>
>>>>>> FILE *file;
>>>>>>
>>>>>> fopen(argv[1], "r+");
>>>>>>
>>>>>> fprintf(file, "\b");
>>>>>
>>>>> You didn't assign anything to `file'.
>>>>
>>>> I didnt notice that, here was me telling him to check that file
>>>> was non-null after fopen() and he didnt even assign it!
>>>
>>> I suspect nertos is a troll trying to get people to trigger the
>>> Windoze bug of crashing when backspacing at the start of a line.
>>
>> If so, he's an incompetent troll; the program won't write a
>> backspace character (unless it does so as an unlikely consequence
>> of undefined behavior). (Conceivably he just didn't test the
>> program because he doesn't want to crash his own system.)
>
> He could be a devious troll, who wants people to correct and run
> his snippet. The fact that he never reappears tends to confirm my
> suspicion.
According to an earlier description here, the bug occurs only on a
console, not on an arbitrary file. Someone would have to fix the
program, then invoke it with an argument of "CON:" (or whatever the
name of the console is under Windows).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
|
|
0
|
|
|
|
Reply
|
kst-u (21469)
|
3/11/2005 8:45:51 PM
|
|
|
11 Replies
44 Views
(page loaded in 0.907 seconds)
|