473,406 Members | 2,769 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,406 software developers and data experts.

Problem with strlen() returning void - need help

3
Hi,

I'm a novice programmer and I've come across the following problem:

I am trying to get strlen for a cosntant char array but I get back a void no matter what I try. The code looks like this:

if (is_define(&lineptr)) {
while (currentline[strlen(currentline)-BKSLSH_OFFSET] == '\\')
lineptr = fgets(currentline, LINE_MAX, fileptr);
}

currentline is a global variable, its definition is:
char currentline[LINE_MAX+1]; /*LINE_MAX = 2048*/

But strlen keeps returning void. I tried using a pointer to the array instead but that didn't help either. I also did the strlen on a separate line, which doesn't help.

I also double checked the contents of currentline:
currentline[0] through currentline[27] are all characters
currentline[28] is a \0

But it doesn't work!

Any ideas anybody?

Thanks,
Gilad
Jan 19 '07 #1
3 1812
giladt
3
Forgot to say I'm writing in C.

Gilad

Hi,

I'm a novice programmer and I've come across the following problem:

I am trying to get strlen for a cosntant char array but I get back a void no matter what I try. The code looks like this:

if (is_define(&lineptr)) {
while (currentline[strlen(currentline)-BKSLSH_OFFSET] == '\\')
lineptr = fgets(currentline, LINE_MAX, fileptr);
}

currentline is a global variable, its definition is:
char currentline[LINE_MAX+1]; /*LINE_MAX = 2048*/

But strlen keeps returning void. I tried using a pointer to the array instead but that didn't help either. I also did the strlen on a separate line, which doesn't help.

I also double checked the contents of currentline:
currentline[0] through currentline[27] are all characters
currentline[28] is a \0

But it doesn't work!

Any ideas anybody?

Thanks,
Gilad
Jan 19 '07 #2
giladt
3
Well, I managed to work around it, but it's still quite puzzling.

What i did to solve it was to assign strlen(currentline) to a variable and then use the variable in the while statement instead and now it works.

Does anyone have an idea why this happens?

Gilad
Jan 19 '07 #3
Ganon11
3,652 Expert 2GB
Not sure. I usually use the built-in std::string class for my strings, which comes with a .length() function. Or, if I need the size of an array in general, I make my own variable to keep track of it. I haven't used strlen().
Jan 19 '07 #4

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

Similar topics

18
by: bArT | last post by:
Hi! I have a problem with such situation. I have a class like below and have some pointers (ptr1 and ptr2). I dynamically allocate memory in constructor and I free in destructor. For one pointer...
15
by: Materialised | last post by:
I am having a problem with the following functions, I've been racking my brains trying to figure out where I am going wrong. What I need to do is return a formatted string with the current date and...
24
by: diego.arias.vel | last post by:
Hi all I have certain problem when I'm doing this: void copy(char *filename) { char *log_file; log_file=filename; strcat(log_file,"-log.txt");
11
by: Fernando Barsoba | last post by:
Hi all, I very much need your help here guys.. I'm working on a IPSec implementation, and when almost finished, I found a considerable problem. I'm sending a particular array + a key to a...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
by: netchtech | last post by:
Hi, I have a record register where I manage records. My problem is that I dont know how to add records to my register. This is the struct I have created that works just fine, so does modify and...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
8
by: Martin the Third | last post by:
Hi, I need some help! I'm writing an infinite-precision floating point library called ipfloat (I know infinite is a misnomer - but arbitrary was taken). A quick overview: I'm storing numbers as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.