473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

can you give me the keyword to represent a space in c language?

dear sir,
i am new to c language. i am developing a program on string function and i want to count the number of 'THE' and 'A' in the given string.
but if i am using 'SPACE BAR' to give space in my string then compiler is ignoring the rest of the following characters.
please guide me what to do??
Nov 16 '10 #1
2 4559
Markus
6,050 Expert 4TB
Well, a look at the code would help.

Here's how I would do it:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main (int argc, char *argv[])
  6. {
  7.     char str[]  = "the thesaurus looked longingly towards the dictionary";
  8.     char *found;
  9.     int  n_the  = 0,
  10.          n_a    = 0;
  11.  
  12.     /* Search for "the" */
  13.     found = strstr(str, "the");
  14.     while (found != NULL)
  15.     {
  16.         n_the++;
  17.  
  18.         /* + 3 = strlen of "the" */
  19.         found = strstr(found + 3, "the");
  20.     }
  21.  
  22.     /* Search for "a" */
  23.     found = strstr(str, "a");
  24.     while (found != NULL)
  25.     {
  26.         n_a++;
  27.  
  28.         found = strstr(found + 1, "a");
  29.     }
  30.  
  31.      printf("n_the: %d\n", n_the);
  32.      printf("n_a:   %d\n", n_a);
  33.  
  34.     return 0;    
  35. }
  36.  
Nov 16 '10 #2
Banfa
9,065 Expert Mod 8TB
I suspect the op is reading stdin using scanf and so is only getting single words because that function uses space as a separator when they really want to read the whole line including spaces.

The solution is to use fgets which will read an entire line because it does not use space as a separator.
Nov 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
42
by: Eric Gunnerson [MS] | last post by:
You may download the new specification at the C# Developer Center (http://msdn.microsoft.com/vcsharp/language). There is a discussion forum for the C# language on that same page. If you don't...
1
by: neverstill | last post by:
hi- I have a table on a page there is 1 row and 2 cells cell 1 has a user control that is basically just a DataList nested in a table o fit's own. then, below that user control I have some <p>...
2
by: Dee | last post by:
Hi I have to <asp:button>'s one on top of the other in a cell of a Table layout. When I put a <br> I get too big a gap. Without it they are touching. The only way I can think of separating them...
1
by: bradjensmith | last post by:
I am importing a pipe delimited text file into MS Access 2002. The text file contains | | aka |space| The resulting table when imported converts the space to a null value. Any suggestions on...
9
by: mike_dba | last post by:
I am using DMS raw. I have a tablespace which is defined with 5 containers each allocated at 1.5 GB for a total of about 7.5 GB. I did a major deletion followed by a reorg and a runstats. I am...
9
by: 440gtx | last post by:
The class keyword created a lot of confusion that resulted in a popular style that says struct is appropriate for POD (plain old data) and class is appropriate for fancier things (member functions,...
2
by: kishoremupparaju | last post by:
what is the use of volatile keyword in c language
43
by: Adem24 | last post by:
The World Joint Programming Language Standardization Committe (WJPLSC) hereby proclaims to the people of the world that a new programming language is needed for the benefit of the whole mankind in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.