Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String manipulations in C 1

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I am trying to read a file name from the cmd line.

%./exec abc.txt

I can read in abc.txt as the argv[1] value. I need to make sure the file is a *.txt file.

I figured, finding the size of argv[1] would give me the number of chars in the file name, and checking the last 3 chars would give me the "txt" part. But sizeof(argv[1]) doesn't work. (Neither does sizeof(argv[1])/sizeof(char) ).

Any help would be appreciated.
 
As I was saying before I was so rudely interrupted:

If you can't use strlen, then count the characters in the string up to the trailing null.

argv[1] is a pointer to char...
 
Sorry, didn't mean to interrupt.

Thanks, don't know why I didn't think of that. Works fine now.
 
You didn't interrupt, the web was doing funny things...

Glad to help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top