ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So I'm making several files, file.1, file.2, all the way up to file.n, and they're going to be created as I reach a certain point in a loop. For example, each time we run through the loop we're going to write a line to a file. When we get to the 100,000,000th line, we'll start on a new file.
I'm not particularly experienced with strings in C, but what I want to do is keep track of which number I'm on, and then create the file names as needed. Here's the source of what I've tried:
But C apparently doesn't like + concatenations. How would I go about adding a number on at the end? (For the moment, I'm assuming we're not going multidigit. That shouldn't be too much of a problem once I've got this bit.)
Just a general comment here: C/C++ is a low-level language. That's a good thing, in my opinion, because it is efficient. When you write code in C or C++ you are basically one step above the assembler. You are moving bits around on the machine. If you want a language that does-what-you-mean then you should use java or perl or something like that. I'm not saying that one language is better than the other, but if you are going to work in the C/C++ world, then you would be well served by an understanding of the way the compiler maps data types and instructions to the underlying hardware. C/C++ are not friendly languages, but they are extremely efficient.
I wasn't looking for advice on which language to use, I was looking for a specific answer to a specific problem. Yes, it would be easier to do in a high-level language, but that doesn't mean I shouldn't learn how to use low-level languages. While your general comment is duly noted, it is was both irrelevant and condescending.
I apologize if the comment seemed condescending. I wasn't offering advice on which language to use; I was offering advice about about how to think about the machine instructions generated by your C source code. One of the biggest problems with C programs is buffer overruns because programmers are not thinking at the binary level.
Also, in your code you should probably be resetting "count" to zero whenever you open a new file. Otherwise you will only ever switch filenames once.
Yeah, I already fixed that. Anyway, that was a small program to transfer my log to a new naming scheme without having to reproduce the logs. I maxed out the file size on a prime list. So today we're debugging the actual program.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.