#include<stdio. h>
int count (char letter, const char *my_string);
void main()
{
int total_l;
char my_string[] = “walla la oh la la la la la long”;
char letter = ‘l’;
total_l = count(letter, my_string);
printf(“There are %d character l in the string\n”, total_l);
}
*required to write a recursive function to count the number of times character ‘l’
appears in a string “walla la oh la la la la la long”
* prints that number on your screen. Your function should be able to;
(a) Count character ‘l’.
(b) Test whether the character ‘l’ is in the string.
(c) If the string had no character at all, we would know immediately that there
were zero occurrences of the character being counted.
(d) If there is any, your program should track the number of occurrence.
7 2035 - int count(char ch, char str[])
-
{
-
int cnt=0;
-
if(strlen(str)==1)
-
{
-
if(str[0]==ch)
-
cnt++;
-
}
-
else
-
{
-
if(str[0]==ch)
-
cnt++;
-
cnt+=foo(ch, str+1);
-
}
-
return cnt;
-
}
-
Banfa 9,065
Recognized Expert Moderator Expert - int count(char ch, char str[])
-
{
-
int cnt=0;
-
if(strlen(str)==1)
-
{
-
if(str[0]==ch)
-
cnt++;
-
}
-
else
-
{
-
if(str[0]==ch)
-
cnt++;
-
cnt+=foo(ch, str+1);
-
}
-
return cnt;
-
}
-
You've called foo instead of count.
I think you will find this goes rather wrong for
count( 'l', "");
which is a specific return case mentioned.
yes, the condition is not strict enough :D
i don't know why he needs a recursive function to count the number of times character ???
sorry for my mistake :) -
int count(char ch, char str[]) -
-
-
{
-
int cnt=0;
- int len=strlen(str);
- if(len<=0)
- {
- return 0;
- }
- else if(len==1)
-
{
-
if(str[0]==ch)
-
cnt++;
-
}
-
else
-
{
-
if(str[0]==ch)
-
cnt++;
-
cnt+=count(ch, str+1);
-
}
-
return cnt;
-
}
-
i've treid already.
but why this error still there.
error C2065: 'strlen' : undeclared identifier
Banfa 9,065
Recognized Expert Moderator Expert
Because you haven't got
#include <string.h>
in your file (at the top preferably)
What is it means by
" missing function header (old-style formal list?)"
Banfa 9,065
Recognized Expert Moderator Expert
Often a ; where there shouldn't be one
should be Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark R |
last post by:
I have one .asp page with a SELECT pulldown list on it and some INPUT
fields. When SUBMIT is clicked the form data is submitted to that same page
and validated. If INPUT fields are empty the asp code will insert a visual
indicator (e.g. *) to convey that the field must be filled in.
However, if the user has made a selection in the pulldown list and has left
an INPUT field empty, when the form reappears after validation, the pulldown
menu...
|
by: Stanley J Mroczek |
last post by:
I Set the EditCommandColumn to Visible=False to stop people who are not
allowed to make any changes to a record. How can set it to Visible=true for
some users? Please answer in VB
Thanks
Stan
|
by: John |
last post by:
This message is popping up at startup and its saying "fatal execution engine
error (0x7927e03e)" Ive tried deleting, reinstalling frameworks, restoring
computer, but I can't use the os cd because i hvae important programs on my
system that would cost alot to replace. I noticed a sql server native client
isnt there like it was before but cant find same program anywhere. Please I
hope someone can help me out. I have a web page that im trying...
|
by: Professor Frink |
last post by:
First off, I apologize if this gets long. I'm simply trying to give you all
enough information to help me out. I'm writing (almost finished, actually),
my first VB.Net application. It's a forms application that is going to be
used to extract data from a legacy system (VSAM based mainframe file
structure), and output data in pipe-delimited record layouts, multiple record
types per file, one file per chosen client. I have been working on...
|
by: Tera |
last post by:
can you please give me the link ?
| |
by: WRH |
last post by:
Hello
I am new to asp but I made some Jscript functions which work
fine. The functions contain some strings used as a registration
key for some apps. It is important that these strings not be
visible to a client using a browser. My question is...can a
knowledgeable browser user view Jscript source code in an asp file?
|
by: Gary |
last post by:
Can somebody help me get the onMouseOut to work in this script? The
onMouseOver works great opening a new window with an image, but I'd like to
get the popup window to close onMouseOut. Is this possible? I'm guessing
it's not because the parent window loses focus when the popup opens.
Is there a better way to do this? I have thumbnails of my kids that I want
to open in a larger format when hoverer over so the grandparents can see
them...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer.
I would greatly appreciate it!!
Thanks!!
<!--put the preloads file here as it must load before the website class...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer.
I would greatly appreciate it!!
Thanks!!
|
by: john6630 |
last post by:
I am trying to get PDO for sqlite to work on my localhost system. I
have modified the PHP5.ini file as shown below and run the following
PHP script. As stated below, it reports the mssql, mysql and sqlite2
drivers but then gives a "could not find driver" exception. Any help
is greatly appreciated. Also, I am concerned if PDO for sqlite is
widely supported by hosting companies, any input or opinions on that?
<?php...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |