LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2009, 01:43 AM   #1
PMR
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
Auto increment an alphanumeric ID in C


Hi everybody..
Can anyone give me any ideas as to how i can auto increment an alphanumeric number? I have files which have ID's of the format - F0001, F0002,....,F0100. Now i have pre existing files till F0008, and when new files are to be added, it must detect the last file ID(which in our case is F0008), increment it and then save the new file with the new ID.

I hope someone can help me soon..

Thanks...
 
Old 05-22-2009, 08:42 AM   #2
soleilarw
Member
 
Registered: Apr 2009
Posts: 107

Rep: Reputation: 19
Using printf formatting code will help you to create the names automatically with leading zeroes. In a similar way you could use system ("ls -1 ./F* > outfile") to gather a list of the relevant files, and then use fopen and fgets and strtok to wade through the contents.
You will certainly need some good documentation to proceed.

Linux Archive

Last edited by soleilarw; 06-18-2009 at 04:03 AM.
 
Old 05-22-2009, 10:40 AM   #3
PMR
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks..but since am new to this, I am finding it a little hard to understand your point..could you be a little more elaborate so that I can have a clear understanding???
 
Old 05-22-2009, 11:08 AM   #4
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
If you are the only reader/writer you could use a function like scandir which gives you a sorted list of the directory entries and then you should be able to work your way from there on.

An other idea could be to store a tiny hidden file in the directory which only contains the last value of the index, and only use this to read/update the current index. If there are more than one reader/writer this could be used as a synchronisation primitive of sorts as well.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cp will copy in any order, not alphanumeric DaveQB Linux - Software 3 01-10-2009 09:15 PM
AUTO_INCREMENT + alphanumeric in MySQL? ta0kira Programming 12 10-03-2008 12:46 PM
how to auto increment 13 digit hexadecimal using script hchoonbeng Linux - Newbie 1 09-24-2008 11:03 PM
arithmetic on alphanumeric in PERL gaynut Programming 2 09-08-2008 09:09 AM
SQLite how to get last "AUTO INCREMENT" value blackman890 Programming 1 12-11-2006 01:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration