473,499 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting substring on given position

151 New Member
I am trying to get the substring or line at a given position.

#include <stdio.h>

int main ()
{
FILE * pFile;
pFile = fopen ( "example.txt" , "w" );
fputs ( "This is an apple.\nWhat can be done on the apple\n" , pFile );
fseek ( pFile , 11, SEEK_SET);
fclose ( pFile );
return 0;
}

using seekg we can point to a particular position but i need substring which ends with newline after the position.
In the above case
I need output should be
apple.\n

How this can be implemented.Thanks in advance.

Manish
Apr 1 '09 #1
2 1594
gpraghuram
1,275 Recognized Expert Top Contributor
After reading the line use strstr to find the position and then use strncpy to copy the string from a required position to end of the line.

Raghu
Apr 1 '09 #2
Man4ish
151 New Member
@gpraghuram
Thank you very much i was looking for getting line which can be done by using getline function. After that i will the method suggested by you.

Manish
Apr 1 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1350
by: Wim Roffal | last post by:
I have a table with a collection of links. For simple duplicates I can check with an index. But I want also check for more than one link from the same domain. So I tried the following: SELECT...
62
31828
by: Jupiter | last post by:
Hey, I would like to know 2 things. 1)Is there any function (in C standard library) that extracts a substring from a string? 2)Is there any function (in C standard library) that returns the...
17
14313
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
3
10293
by: Tim Soliday | last post by:
I have been looking at regular expressions lately, and I'm hoping that maybe someone could help me? I am trying to find the position of a substring, and then returning the substring including...
2
2004
by: David Filion | last post by:
Hi, I have a question about substring(), when I run the following query: prepaid=# select substring('15148300', 0, 5); substring ----------- 1514 (1 row)
2
6399
by: mallard134 | last post by:
Could someone please help a newbee vb programmer with a question that is driving me crazy. I am trying to understand a line of code that is supposed to return the domain portion of a valid email...
1
9469
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
3
2916
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem in searching out a particular substring in a string. Here the code: --------------------- <html> <script> var tmpString=" ";
4
2362
by: N00b13 | last post by:
I have a great JS menu but I have to update every page each time I want to change a link. Is there a way to store my links in a file and call it so i only change that file? (what I have tried so far...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.