LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2008, 03:07 PM   #1
hk20
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Rep: Reputation: 0
C prog, null strings question


Hello, I am having a problem determining when a string is empty:

ex: input file

"Test1"
"Test2"
""
"Test4"
"Test5"
""
"Test7"

How can I detect those 2 empty strings?

Note: The input has quotes around the letters.


#define QUOTES ""
int i;

while(fscanf(testStream, "%s", &testnum[i]) == 1)
i++;

for(i=0; i<20; i++)
{
result = strcmp(QUOTES, testnum[i]);
if(result == 0)
printf("found string\n"); //print i number of times quotes found.
}


the above only detects 5 strings, not the other 2.

Any ideas? Thank You.
 
Old 08-30-2008, 03:50 PM   #2
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
about this:
Code:
#define QUOTES ""
This is empty string (length is zero), not string containing two quotes.
If you want two quotes, then you declare string like this:
Code:
const char* str = "\"\"";
or
Code:
#define QUOTES "\"\""
You can also try loading strings line-by-line using fgets.
 
Old 08-30-2008, 03:57 PM   #3
hk20
LQ Newbie
 
Registered: Sep 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the help! That fixed it
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ; in command strings question. Thaidog Linux - General 2 04-21-2007 07:01 PM
Question about malloc - free and exit prog. pentalive Programming 6 05-08-2006 09:55 PM
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
strings question sibtay Programming 7 10-01-2004 10:37 AM
Help with a script (question on strings) wswartz Linux - General 3 07-11-2004 08:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration