473,385 Members | 1,372 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,385 software developers and data experts.

need help for simple c++ programming



As myfile.txt is the required filename, i try to extract the string
"myfile.txt" to variable "filename" of type char from buffer
i1: position of "m" in "myfile.txt"
i2: position of the last "t" in "myfile.txt"
buffer: a character array containing many words in
********************************************** while(i1 < i2) {
strcat( filename, buffer[i1] );
i1++;
}; *********************************************** The above
lines generate error. I think this is because buffer[i1], buffer[i1+1],
...... are some characters without the ending '\0' and therefore cannot be
used in the strcat function. But is there any ways to achieve my purpose? or
i simply go to a completely wrong direction? Thanks for your kind attention.

Jul 22 '05 #1
1 1698

"news.hku.hk" <bi******@hkusua.hku.hk> wrote in message
news:3f********@newsgate.hku.hk...


As myfile.txt is the required filename, i try to extract the string
"myfile.txt" to variable "filename" of type char from buffer
i1: position of "m" in "myfile.txt"
i2: position of the last "t" in "myfile.txt"
buffer: a character array containing many words in
********************************************** while(i1 < i2) {
strcat( filename, buffer[i1] );
i1++;
}; *********************************************** The above
lines generate error. I think this is because buffer[i1], buffer[i1+1],
..... are some characters without the ending '\0' and therefore cannot be
used in the strcat function. But is there any ways to achieve my purpose? or i simply go to a completely wrong direction? Thanks for your kind attention.

buffer[i1] is a char NOT a null terminated string of chars. Remember that
there is no difference between a char and an int (except that a char might
be one or two bytes long instead of two or four bytes long (but you cannot
rely on this)). To do what you are trying to do you could do the
following:

while(i1 < i2) {
filename[i1]= buffer[i1] ; // Assign the array elements char
by char
i1++;
};

Or you could force buffer to be a NULL terminated string and use the string
functions...

buffer[i2]='\0'; // Null terminate the array of chars makeing a 'string'
strcpy(filename,buffer); // Now just use strcpy to copy into the filename
array (null terminated)

Sean

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
3
by: xrongor | last post by:
hi. i need a simple, hopefully free html editor that besides the standard features has the following properties: allows frames. and will allow me to create a "directory" based on data...
1
by: Mathias Goldau | last post by:
Hi, Can someone tell me where I find some material (e.g. a compiler with graphics.h and conio.h (for free)) related to graphic programming BGI-like, and sound programming (not PC-speaker). The...
5
by: Mr. X | last post by:
Hello, Let me begin by saying that I am a strong advocate of science, math and engineering students learning to program... just a skill that they need to experience even if they go another path....
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
0
by: asil2003 | last post by:
Learn how to develop an application protocol as well as build an application over UNIX (Linux) socket. 2. Project Description: Build an on-line personal schedule manager In this programming...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
25
by: vikram Bhuskute | last post by:
I have plans to train some students for C in coming weeks. I am badly looking for C programming assignments fot them. Need 1) lots of them per topiic 2) Should be doable for beginners thanks...
6
kenobewan
by: kenobewan | last post by:
Congratulations! You are one of the few who realise that over 80% of errors are simple and easy to fix. It is important to realise this as it can save a lot of time. Time that could be wasted making...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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...
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...

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.