pointers and files

P

pooja

Hi
I m pooja.I m working on a prj in C.
I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .


--------------------------------------------------------------------------------
 
T

Tom St Denis

pooja said:
Hi
I m pooja.I m working on a prj in C.
I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .

Give me your mailing address and I'll mail you a free keyboard with a
working space, ' and a non-sticky comma key.

;-)

Tom
 
P

Peter Pichler

Tom St Denis said:
Give me your mailing address and I'll mail you a free keyboard with a
working space, ' and a non-sticky comma key.

While you are at that, you can also send him/her a free spelling chequer
(he!) as well ;-)

To the OP: I for one have no idea what you are talking about.

Peter
 
N

nrk

pooja said:
Hi
I m pooja.I m working on a prj in C.
I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .

This is not a chat board. Don't expect an instant response. Please post
and wait a few days (typically a week should be good) before re-posting the
same question.

Your question is unclear. Post a small, compilable piece of code that shows
the problem, and try to explain the problem in context, referring to the
code that you post.

-nrk.
 
T

Thomas Matthews

pooja said:
Hi
I m pooja.I m working on a prj in C.
Hi. If you type "working", you can type "project"; same amount
of letters. Or you can be consistent and abbreviate everything:
I'm wrk prj C.

I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.

In C, there are:
pointers to char
pointers to FILE
file or stream offsets
pointers to file names (which are arrays of char)
Which one of the above are you talking about?

Pointers to char do not point to files.
Pointers to FILE are not used for text.
File or stream offsets tell the position within a file, but
you can't dereference them. You can use "fseek" or any of
the file positioning functions.

Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .

If "include" is at position 3000 in a file, then you
can use fgetc or other stream functions to get the
character from the file.

Please read the welcome.txt and FAQs below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
K

Kelsey Bjarnason

Hi
I m pooja.I m working on a prj in C.
I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .

This makes absolutely no sense. char pointers are in memory, not in
files, for starters. Second, the only way all those things could be at
the same address is if you employed some form of magic compression that
stored 8 bytes in one byte.

Try posting a small snippet of code that shows the actual problem you're
having and maybe we can see what's going wrong.
 
R

Randy Howard

Hi
I m pooja.I m working on a prj in C.

I m ! wanting to read ur garbage. Post in English, or at least some
actual language someone might understand. Show source
source code that is the smallest possible bit of your program that
shows the problem.
 
N

Nitin Bhardwaj

Hi
I m pooja.I m working on a prj in C.
I m unable to increment a char pointer in a file, it gives the same
address as that of the first char.Eg if # is on loc 3000 then i,n ,c
,l,u,d,e are on same address.Can any one plz help .


--------------------------------------------------------------------------------
Hello Pooja,

u don't have pointers to a file actually.[ actually we have pointers
to stream ,and the stream is connected to the file on the harddisk -
thats what happens when u call fopen(...) ]

So,first read-in the line( or data etc.) from the file into some
buffer into the memory( ur RAM ) and then u can
increment/decrement,run whatever you wanna do with them.

most probably you might be working on Turbo C++ IDE.
So,if you insist on incrementing the file-pointer,then you can use :

fp->charp++;

[ charp is a member of FILE structure,if you look into the header file
'stdio.h' where the struct FILE is declared ]

Hope this clears your doubts

( mail me at : (e-mail address removed))
 
I

Irrwahn Grausewitz

So,if you insist on incrementing the file-pointer,then you can use :

fp->charp++;

Never ever try this at home!
[ charp is a member of FILE structure,if you look into the header file
'stdio.h' where the struct FILE is declared ]

The internals of the FILE structure are implementation dependent.
You should treat FILE as an opaque data type and never inspect
or change its members directly.

Regards
 
C

Christopher Benson-Manica

Irrwahn Grausewitz said:
You should treat FILE as an opaque data type and never inspect
or change its members directly.

With the meaning of the word "never" in this context being
implementation and programmer defined :)
 
J

Jeremy Yallop

Irrwahn said:
Never ever try this at home!

It's okay, it's guaranteed not to work. The identifier 'charp' is in
the user's namespace, so (e.g.) the following has to work correctly.

#define charp 0
#include <stdio.h>

Jeremy.
 
N

Nitin Bhardwaj

Irrwahn Grausewitz said:
So,if you insist on incrementing the file-pointer,then you can use :

fp->charp++;
[ charp is a member of FILE structure,if you look into the header file
'stdio.h' where the struct FILE is declared ]

The internals of the FILE structure are implementation dependent.
You should treat FILE as an opaque data type and never inspect
or change its members directly.

Thats why i had mentioned a particular **implementation** [ i.e Turbo
C++ IDE ].

I'd just suggested an easier way, when someone is hellbent to jump into
a well :)
 
R

Richard Bos

Irrwahn Grausewitz said:
So,if you insist on incrementing the file-pointer,then you can use :

fp->charp++;
[ charp is a member of FILE structure,if you look into the header file
'stdio.h' where the struct FILE is declared ]

The internals of the FILE structure are implementation dependent.
You should treat FILE as an opaque data type and never inspect
or change its members directly.

Thats why i had mentioned a particular **implementation** [ i.e Turbo
C++ IDE ].

Actually, you didn't. By implication, your solution requires _your_
version of Turbo C++ (btw, this group is about C, not C++; comp.lang.c++
is thataway ->) for _your_ OS, and not necessarily any other edition.
Since the contents of a FILE are not defined by the Standard, Borland
can legitimately (and perhaps for good reasons) change them between
versions, and I'd be even less surprised if it changed depending on the
target OS.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top