Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-2008, 10:52 AM
Reigan Reigan is offline
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
Reigan is on a distinguished road
Smile text program

I need code, who take some string of character, and to compare that a .txt file.
example:

string = "qwe"
.txt file = ''axcbhyqweklmnpouyxsqwelkopyqqwesd''
_____________((7)__________(20)_____(29)

I need then program find in this text file a letters: ''qwe'' and call the number of that place, where this letter start in text.

result must be:
7, 20, 29

please help me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-13-2008, 11:13 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: text program

To get the data, use System.IO.File.ReadAllText("FullPathNameOfTextFile Here.txt"). You can use an "include" statement here. To search for the string, look at the methods inside the string. Try Contains() to see if the string exists, then use IndexOf() to get the index of each. Remove the occurrence in a separate copy of the text, then search again to find the next one.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-14-2008, 12:49 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,421
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: text program

If you are using C++, there are some string functions that can do this for you quite easily. If you are using C, it will be a bit trickier. Not knowing the language or what you've done so far, it's tough to help.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-14-2008, 01:11 PM
R-G's Avatar   
R-G R-G is offline
Programmer
 
Join Date: Apr 2007
Location: Europe
Posts: 144
Rep Power: 0
R-G is an unknown quantity at this point
Default Problem Solution

I don't know which computer programming language you would prefer for a solution of such a problem. I hope that this source software code algorithm written in the computer programming language Assembly will fit your wishes.

Code:
.xlist
include         stdlib.a
includelib      stdlib.lib
.list

wp              textequ <word ptr>

dseg            segment para public 'data'

StrPtr          dword   ?
FileName        dword   ?
LineCnt         dword   ?

FVar            filevar {}

InputLine       byte    1024 dup (?)
dseg            ends


cseg            segment para public 'code'
assume  cs:cseg
ds:dseg


ReadLn          proc
push    es
push    ax
push    di
push    bx

lesi    FVar
mov     bx
0
ReadLp:         fgetc
jc      EndRead

cmp     al
cr
je      ReadLp
cmp     al
lf
je      EndRead

mov     InputLine[bx]
al
inc     bx
jmp     ReadLp


EndRead:        mov     InputLine[bx]
0
pop     bx
pop     di
pop     ax
pop     es
ret
ReadLn          endp


Main            proc
mov     ax
dseg
mov     ds
ax
mov     es
ax
meminit

argc
cmp     cx
2
je      GoodArgs
print
byte    "Usage: Software_name 'string' filename"
cr
lf
0
jmp     Quit

GoodArgs:       mov     ax
1
argv
mov     wp StrPtr
di
mov     wp StrPtr+2
es

mov     ax
2
argv
mov     wp Filename
di
mov     wp Filename+2
es


mov     ax
0
mov     si
wp FileName
mov     dx
wp FileName+2
lesi    Fvar
fopen
jc      BadOpen


mov     wp LineCnt
0
mov     wp LineCnt+2
0
SearchLp:       call    ReadLn
jc      AtEOF


add     wp LineCnt
1
adc     wp LineCnt+2
0


lesi    InputLine
mov     dx
wp StrPtr+2
mov     si
wp StrPtr
strstr
jc      SearchLp


printf
byte    "Found '%^s' at line %ld\n"
0
dword   StrPtr
LineCnt
jmp     SearchLp


AtEOF:          lesi    FVar
fclose
jmp     Quit

BadOpen:        printf
byte    "Error attempting to open %^s\n"
cr
lf
0
dword   FileName


Quit:           ExitPgm
Main            endp

cseg            ends

sseg            segment para stack 'stack'
stk             db      1024 dup ("stack   ")
sseg            ends

zzzzzzseg       segment para public 'zzzzzz'
LastBytes       db      16 dup (?)
zzzzzzseg       ends
end     Main
__________________
Like an angel without a sense of mercy.

Last edited by R-G; 04-15-2008 at 07:21 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 06:20 AM
Reigan Reigan is offline
Newbie
 
Join Date: Apr 2008
Posts: 2
Rep Power: 0
Reigan is on a distinguished road
Default Re: text program

How to get amount of character from .txt file in c++?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-19-2008, 07:50 AM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default Re: text program

Quote:
Originally Posted by Reigan View Post
How to get amount of character from .txt file in c++?
If you mean to count all characters, you could probably just read each line, add them together into one string, and use length():

Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(int argc,char *argv[]){
  string fileContents="",tempContents="";
  ifstream readFile();
  readFile.open("file_name.txt");
  while(!readFile.eof()){
    getline(readFile,tempContents);
    fileContents+=tempContents;
  }
  cout<<"The amount of characters in the file should be: ";
  cout<<fileContents.length();
  cin.ignore();
  return 0;
}
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 09:00 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: text program

Or, you could just use an integer variable to count the lines.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Starting C# with C# 2008 Express Edition Jordan CSharp Tutorials 19 08-08-2008 01:48 PM
How to style fonts of a text in a simple page? c0de Tutorials 3 09-15-2007 11:08 PM
Program to pass data from text file to table. sania21 Java Help 3 05-28-2007 09:32 AM


All times are GMT -5. The time now is 11:08 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads