473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

unwanted value in file reading

if i read a file whenever i read it line by line while reading i try to check it with some string by the strcmp command .This is like thats
the string to be read from file is "rohan sharma".
while(fgets(bufrftext,1200,fp)
{ printf("the read string is :%s"bufftext");
i=strcmp(bufftext,"rohan sharma")

printf("the value of i :%d",i);
}

  • the expected o/p is :
  • the read string is : rohan sharma //this o/p comes
  • the value of i : 0// this o/p is always 1.

please try to help me in this issue if want to remove the unwanted character that comes along the string which you read from file that makes string comparision impossible.
Jan 23 '10 #1

✓ answered by johny10151981

As donbock says there is a new line at the end of bufrftex.
But you are comparing with "rohan sharma" which actually contain '\0' at the end of line. It may not contain '\n' at the end of line if it is the last line of the file.

Here what you can do
1. get the lenght of bufrftex.
2. add '\0' at the length position. i.e
len=strlen(bufrftex);
bufrftex[len]='\0';

3. then you compare. you will get desired result.

By the way, you can check value of bufrftex while debugging one by one.

Regrds,
Johny

2 1692
donbock
2,426 Expert 2GB
Perhaps there is a newline at the end of bufftext.

If nothing seems to work, then you could print out each successive byte in bufftext as a number ("%02x"). This should make it easy to see if there is something unexpected in there.
Jan 24 '10 #2
johny10151981
1,059 1GB
As donbock says there is a new line at the end of bufrftex.
But you are comparing with "rohan sharma" which actually contain '\0' at the end of line. It may not contain '\n' at the end of line if it is the last line of the file.

Here what you can do
1. get the lenght of bufrftex.
2. add '\0' at the length position. i.e
len=strlen(bufrftex);
bufrftex[len]='\0';

3. then you compare. you will get desired result.

By the way, you can check value of bufrftex while debugging one by one.

Regrds,
Johny
Jan 24 '10 #3

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

Similar topics

2
by: Jon Whittlestone | last post by:
hi there. I am getting two > characters and i really can't understand why they are there - see http://www.jonwhittlestone.co.uk/portfolio%20files/wminproperty/landlordAddProperty.php It is...
3
by: StopBsod | last post by:
Hello group, I use XSLT to output a unix shell script based on the content of an XML file : The XSLT : <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">...
2
by: Max | last post by:
I'm reading some files in a directory using php code for the end result of allowing these files to be deleted. The problem is some of the file names have hyphens in them, and this cannot be...
5
by: Andrew | last post by:
Hello, Is there anyway to detect when scanf implicitly casts a value? If I have a scanf call which expects a float and is passed a double I believe that testing the scanf call with...
4
by: David Beck | last post by:
I donwnload some files for processing every day that have unwanted characters in them. In VB6 I use the InputB to read in the text and the StrConv. vLinesFromFile =...
8
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to...
16
by: lovecreatesbeauty | last post by:
/* When should we worry about the unwanted chars in input stream? Can we predicate this kind of behavior and prevent it before debugging and testing? What's the guideline for dealing with it? ...
0
by: Abhinay | last post by:
hi, this is abhinay, i have data ie xml file Ex: <root> <child1> <cc1>aaa</cc1> </child1>
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
4
by: ljsmith91 | last post by:
I am reading in a file that has a list that of items. The items I place into a scalar for print but when i do, there is an extra unwanted charachter that shows up at the end of each item. It looks to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.