Sponsored Content
Full Discussion: Find out the error
Top Forums Programming Find out the error Post 302479106 by kermit on Thursday 9th of December 2010 09:34:08 PM
Old 12-09-2010
Well your first problem is that 'If' is not a keyword in C, whereas 'if' is. As an aside, you ought not put your call to strlen() inside the loop like you have. Change your code from:
Code:
for(i=0;i< strlen(the_file);++i)

to:
Code:
size_t len = strlen(the_file);
    for (i = 0; i < len; ++i) {

The reason for this is that strlen() walks through the string _every_ time you call it. And so if you call it inside the loop, you get a lot of overhead associated with that, because you are doing it a lot of times. Better to call strlen() once, save the result, and use it later within the loop.

Last edited by kermit; 12-09-2010 at 10:45 PM..
This User Gave Thanks to kermit For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error when using if [ find '

I am trying to issue the following command in script: if ; then and I am getting the following error: bad number Any ideas Rgds Joe (4 Replies)
Discussion started by: berminator
4 Replies

2. UNIX for Dummies Questions & Answers

error in a remote find

2 AIX servers (AIX 5.3). From local server, I need to manage remote files. But I have some errors with find : # rsh remoteserver find /directory -name filename is OK : I can see the remote file BUT : # rsh remoteserver find /directory -name filename -exec ls -l {} \; fails : I have : find :... (5 Replies)
Discussion started by: annemar
5 Replies

3. AIX

Error: could not find any of these C compilers

Hi, While trying to configure Apache Web Server on P630 Server i am getting the below message "Creating Makefile in src + configured for AIX 5.2 platform Error: could not find any of these C compilers anywhere in your PATH: gcc cc acc c89 Configure terminated" when i did a "lslpp -l... (2 Replies)
Discussion started by: cherryven
2 Replies

4. Shell Programming and Scripting

find error

I have a directory that our applications are continuely generate new file to it , some files hv a word "error" in content , I would like to find out which file hv this word and send me notify mail to inform me which file hv this word , currently , I have a stupid script to grep the word , the... (1 Reply)
Discussion started by: ust
1 Replies

5. Shell Programming and Scripting

syntax error not able to find why

Hi Guru's here is part of my shell script where the error is coming. function daemon_start { daemon="" clear :<<COMMENT Meenakshi 25-Jun Code Cleanup IA - code comented - Start echo " `date` ... (1 Reply)
Discussion started by: namishtiwari
1 Replies

6. UNIX for Advanced & Expert Users

error with find

for FNAME in `find . -type f -exec grep -il unixs317 {} \;`; do C=`grep -c unixs317 ${FNAME}`; echo "${C}:${FNAME}" >> output.txt; done When I run this command and a directory is empty it is returning an error and just does nothing more. How can I continue with my search even when it find... (3 Replies)
Discussion started by: TimHortons
3 Replies

7. UNIX for Dummies Questions & Answers

find - link - error

Have a random question: In simple terms I have a find command on a dir: /path/user/data/ /path/user is a link to: /tmp/storage/ The find command outputs the files it finds as: /path/user/data/file What I need is: /tmp/storage/file Is there a way to "resolve" the Unix... (5 Replies)
Discussion started by: Cranie
5 Replies

8. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

9. Shell Programming and Scripting

find command error

Hi, We have a shell script which looks into a directroy for any folder older than 30 days and removes them. The command being used is find $ARCHIVE_DIR -type d -mtime +$PURGE_HIST_DAYS -exec rm -rf {} \; It removes some folders but then throw below errors for others: find:... (2 Replies)
Discussion started by: DejaVu
2 Replies

10. Shell Programming and Scripting

Cannot find Error

Today is my first day in shell scripting. I am not able to find error. Need Help! Error is :- syntax error near unexpected token `then' test.sh: line 50: ` if; then echo "Enter Path o(if empty file will be unzipped to /var/www/):" read path echo... (3 Replies)
Discussion started by: sunny2802
3 Replies
strlen(3)						     Library Functions Manual							 strlen(3)

NAME
strlen - Finds the length of a string LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <string.h> size_t strlen( const char *s); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: strlen(): ISO C, XPG4 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the string. DESCRIPTION
The strlen() function returns the number of bytes in the string pointed to by the s parameter. The string length value does not include the terminating null character. Note If you pass a NULL pointer as the const char * parameter to the strlen function, the function generates a segmentation violation. To avoid the segmentation violation and cause the function to return 0 (zero), change the NULL pointer treatment for the process before issuing the call to the strlen function, as follows: Include the system header file sys/uswitch.h. Call the uswitch function, as described in the uswitch(2) reference page. The following program illustrates this procedure: #include <stdio.h> #include <sys/types.h> #include <sys/uswitch.h> main() { size_t retval; int uswitch_val; uswitch_val = uswitch(USC_GET,0); uswitch(USC_SET, uswitch_val | USW_NULLP); retval = strlen(NULL); RETURN VALUES
On successful completion, the strlen() function returns the number of characters (bytes) in the string to which the s parameter points. Current industry standards specify that no value be reserved to indicate an error. RELATED INFORMATION
Functions: string(3), uswitch(2), wcslen(3) Standards: standards(5) delim off strlen(3)
All times are GMT -4. The time now is 04:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy