vendredi 17 avril 2015

find the number of strings in 2D array of strings

Given an array of strings, i need to find out the number of strings in it.


I followed this


but this doesn't work if i am passing this into a function.


here's the code i tried



#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int f1(char* input1[])
{

string s="";

cout<<sizeof(input1)<<endl; //print 4
cout<<sizeof(char*)<<endl; //print 4
int l=sizeof(input1) / sizeof(char*);
//giving l=1 here but should be 8
}

int main()
{
char *str2[]={"baba","sf","dfvf","fbfebgergrg","afvdfvfv","we","kkhhff","L"};
int l=sizeof(str2) / sizeof(char*);
cout<<l<<endl; //print 8
cout<<sizeof(str2)<<endl; //print 32
cout<<sizeof(char*)<<endl; //print 4
f1(str2);
}

Aucun commentaire:

Enregistrer un commentaire