Advertisement

Getting a string array size from a parsed string

Started by February 26, 2001 06:56 PM
1 comment, last by SikCiv 23 years, 11 months ago
Say u have a function like so.. void func() { char szString[64]; GetFileName(szString); } // How do I get the array size of the parsed string? // The below code returns 4 (the size of the pointer or something) void GetFileName(char *szString) { // Get the array size of the string int len = sizeof(szString); // Ive also tried.. lev = sizeof(*szString); // And.. lev = sizeof(&szString); // len returns ''4'' // Need len to be ''64'' .... .... } Is there a way to do it properly?

  Downloads:  ZeroOne Realm

There's a builtin C function to do exactly this!
It's called "STRLEN".

usage:
strlen(s1) Returns the length of string s1


    #include <stdio.h>#include <string.h>void main(void){   char s1[80];   gets(s1);   printf("length of string: %d\n", strlen(s1));}  


Ptim

There is no off position on
the genius switch


Edited by - ptim on February 26, 2001 8:08:43 PM
-=-=-=-A M I N O T M E R C I F U L ! ? ! ?
Advertisement
Worth noting is that the value returned doesn''t count the 0x00 at the end of the string. So if you are checking it for enough room to copy it or allocating space for it you have to add one to the length that strlen gives you.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement