Sponsored Content
Top Forums Programming Traversing in Array of pointers Post 302429368 by showkat161 on Monday 14th of June 2010 08:51:42 AM
Old 06-14-2010
yes you are right.. So if I include the statement that you used to get the count of n then combination of you and me will make this program even better- right?
Code:
# include <stdio.h>
# include <string.h>
int main(void)
{
char *s[] = {
"We will teach you how to..",
"Move a mountain",
"Level a building",
"Erase the past",
"Make a million",
"....all through C!"
};
int count=0,i=0;
size_t n = (sizeof s/sizeof(char *))-1;
while ( n >=0) {
   if (*((s[n])+i++)=='e') { ++count;}
    else
 if(*((s[n])+i)=='\0'){
  n--;i=0;}
}
printf("count of e's : %d\n",count);
return 0;
}

Code tags please.

Last edited by jim mcnamara; 06-14-2010 at 10:05 AM.. Reason: Arrays start from zero so need to adjust the value of n accordingly
 

10 More Discussions You Might Find Interesting

1. Programming

Pointers and array

hi all, let say i have a pointer exit, and this exit will store some value. how can i store the value that the pointer points to into an array and then print them out from the array. thanks in advance (2 Replies)
Discussion started by: dianazheng
2 Replies

2. UNIX for Dummies Questions & Answers

Traversing a file system

I'm pretty new at this UNIX stuff, and this may be a simple question but I'm kind of stuck :confused: Let's say I have a large directory structure of .essay files, where I saved all of the essays that I did over the last few years. Not all of the .essay files are in the same directory (all... (1 Reply)
Discussion started by: hooj
1 Replies

3. Programming

Vector Traversing

Hi i have the following structure struct S { char Mod_num; char val; char chr_nm_cd; } I am reading a 2GB file and inserting into the structure and writing into a vector. I feel like only vector will be a right option. I tried with multimap but it is memory intensive and hence i... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

4. UNIX for Dummies Questions & Answers

script for traversing directory

hi please suggest a korn script which will traverse all subdirectory in the current directory? (2 Replies)
Discussion started by: ilayans
2 Replies

5. Programming

Problem with array of pointers

Hi All, I am using the array of pointers and storing the address of string.This is a global list. So i am using extern to give the reference of this list to another file and using reading the data from this string. But list is being corrupted and string is missing some characters in... (2 Replies)
Discussion started by: lovevijay03
2 Replies

6. Homework & Coursework Questions

Problem while traversing directories

I was given to create a backup of all files in a given directory(command line argument) into say /home/vishal/back and the back up files must be accordingly to the extension of the file i.e pdf files are saved in back/pdf doc files back/doc etc . I gave a recursive function to traverse through the... (1 Reply)
Discussion started by: davis7son
1 Replies

7. Shell Programming and Scripting

traversing a string

I am writing a script which will read a word and say how many vowels and consonants does the word contain. but i dont know how to traverse a string in shell scripting. if it was in C i'd have done something like this: cout<<"plz enter the word"<<endl; cin>>word; int consonants, vowels;... (4 Replies)
Discussion started by: nishrestha
4 Replies

8. Programming

Pointers and array

Hello, I read from a book exercise for a challenge. How to print out each letter of char array a by two different pointers pa and ppa in the example? I have tried my code for letter "r" by testing without full understanding as only the first one worked. #include<stdio.h> int main() { char... (17 Replies)
Discussion started by: yifangt
17 Replies

9. Programming

Traversing member of structure of vector C++

Hello, I want to loop thru a vector composed of many entries as structure, which contains sequenceID and sequence. At looping, delete any structure if the sequence is a perfect-match substring of another sequence of any other structure, so that the resulted vector contains only unique sequences.... (1 Reply)
Discussion started by: yifangt
1 Replies

10. Programming

How to Declare an array of function pointers?

I am attempting to create an array of function pointers. The examples I follow to do this are from: support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c ... (3 Replies)
Discussion started by: spflanze
3 Replies
Data::Stream::Bulk::Array(3pm)				User Contributed Perl Documentation			    Data::Stream::Bulk::Array(3pm)

NAME
Data::Stream::Bulk::Array - Data::Stream::Bulk wrapper for simple arrays. VERSION
version 0.11 SYNOPSIS
return Data::Stream::Bulk::Array->new( array => @results, ); DESCRIPTION
This implementation of the Data::Stream::Bulk api wraps an array. The use case is to keep the consumer of the data set implementation agnostic so that it can deal with larger data sets if they are encountered, but still retain most of the simplicity when the current data set easily fits in memory. ATTRIBUTES
array The array reference to wrap. METHODS
next Returns the array reference on the first invocation, and nothing thereafter. is_done Returns true if "next" has been called. list_cat Squishes adjacent arrays into a new array. filter $filter Immediately applies $filter to the internal array and returns $self. loaded Returns true AUTHOR
Yuval Kogman <nothingmuch@woobling.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Yuval Kogman. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-02-14 Data::Stream::Bulk::Array(3pm)
All times are GMT -4. The time now is 11:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy