473,406 Members | 2,894 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,406 software developers and data experts.

How to Create Bool Function and Check the File for specific characters?

john dhoe
I got stuck with creating 2 functions:
- bool oneAt(char email[] ); - to check if each email has ONLY one “@” character.
- bool oneDot(char* email); - to check if each email has ONLY one “.” (dot).

Can somebody help?

Here's my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cstring>
  6. #include <sstream>
  7. #include <stdlib.h>
  8. using namespace std;
  9.  
  10. bool oneAt(char email[]);
  11.  
  12. const unsigned MaxRecLen = 80;
  13. const unsigned MaxFileName = 200;
  14.  
  15. int main()
  16. {
  17.     ifstream inF;
  18.     ofstream of;
  19.  
  20.     char infile[ MaxFileName + 1 ],
  21.          outfile [ MaxFileName + 1 ];
  22.     char email [ MaxRecLen ];
  23.  
  24.  
  25.         cout << "Enter File Name: ";
  26.         cin >> infile;
  27.         cout << "Output File: ";
  28.         cin >> outfile;
  29.  
  30.     inF.open( infile );    
  31.     of.open( outfile );
  32.  
  33.     inF.getline (email, MaxRecLen );
  34.  
  35.     while (strlen(email)){
  36.         if(strlen(email) < 0){
  37.         }
  38.         of << email << endl;
  39.         inF.getline(email, MaxRecLen);
  40.     }
  41.     inF.close();   
  42.     of.close();
  43.     return 0;
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
Jan 29 '11 #1
7 2153
Markus
6,050 Expert 4TB
We won't write the code for us. Show us what you have tried.
Jan 30 '11 #2
Didn't I write the code above?:-)
Jan 30 '11 #3
Markus
6,050 Expert 4TB
Sure, but the code above isn't the code you're having trouble with.
Jan 30 '11 #4
Exactly. I can't go further, because I don't know how. How can I write code if I don't know what to write?
That's why I posted the problem here...
Jan 30 '11 #5
Rabbit
12,516 Expert Mod 8TB
The general idea is to use a loop to step through the array and check the ASCII character code while keeping a count of the character you're looking for.
Jan 30 '11 #6
hi! could you please check my code & tell why it's not working? it doesn't output what it is supposed to... here's my code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <sstream>
  5. #include<conio.h>
  6. using namespace std;
  7.  
  8.  
  9. const unsigned MaxRecLen = 80;
  10. const unsigned MaxFileName = 200;
  11. bool oneAt(char email[])
  12.     {
  13.     int atFound = 0;
  14.  
  15.     if(email[0] == '@')
  16.         atFound=2;
  17.  
  18.     for(int i = 0; i < strlen(email); i++)
  19.     {
  20.     if(email[i] == '@')
  21.     atFound++;
  22.     }
  23.     if(atFound>1)
  24.         return false;
  25.     else
  26.         return true;            
  27.  }
  28. void main()
  29. {
  30.     ifstream inF;
  31.     ofstream of;
  32.  
  33.     char infile[ MaxFileName + 1 ],
  34.          outfile [ MaxFileName + 1 ];
  35.     char email [ MaxRecLen ];    
  36.  
  37.         cout << "Enter File Name: ";
  38.         cin >> infile;    
  39.  
  40.     inF.open( infile );    
  41.     of.open( outfile );
  42.  
  43. bool a;
  44.  
  45.     while (!inF.eof() )    
  46.      {
  47.       //   if(oneAt(inF.getline (email, MaxRecLen) ))
  48.          cout<<inF.getline (email, MaxRecLen );
  49.  
  50.  
  51.          /*if(oneAt(b))
  52.              cout << b << endl;*/
  53.      }    
  54.     inF.close();   
  55.     of.close();
  56.  
  57.     getch();
  58. }
  59.  
  60.  
  61.  
  62.  
Feb 2 '11 #7
Rabbit
12,516 Expert Mod 8TB
It would help if we knew what it was outputting that it's not supposed to.
Feb 2 '11 #8

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

Similar topics

5
by: Sugapablo | last post by:
file() works great, until you start looking at file that are very large, say 134MB. Is there any function that will return an array for each line of a file, but only for lines given as...
0
by: Petri Savolainen | last post by:
After reading the manuals and googling around a bit, I thought I'd use the 'compile' built-in to create a code object. Then, using either new.function() or types.FunctionType(), create a function...
17
by: Behrang Dadsetan | last post by:
Hi all, I would like deleting specific characters from a string. As an example, I would like to delete all of the '@' '&' in the string 'You are ben@orange?enter&your&code' so that it becomes...
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
7
by: Jimakos Bilakis | last post by:
Hi guys! I'm using the C++ Builder 6 Enterprise Edition where I create some tables in Paradox and with the help of a structure i pass my data from the form (Edit boxes) to the Paradox table with...
0
ADezii
by: ADezii | last post by:
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a...
6
by: mohamed azaz | last post by:
hi I want to know how can I create a simple doc file to drive D in Harddisk by using c++ code please answer me Quickly bye bye
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
18
by: mamul | last post by:
Hi, Please help me. I want to create a function taking file as an argument and open that file in the browser. wfstream file_stream; void function(string filepath) {
2
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.