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

Problem Taking input:(

I'm new in c programming. I am writing a program which reads the ID3 V1
tag from a mp3 file and edits it. But everytime i try to take inputs ,
the first character of my album contains 0. So, it doesn't write
anything at the start of album field. So, winamp cannot recognize the
album name. Can someone pls help me? :-(

The code for tag input and edit is:

void edittag(long loc,char name[]){
FILE *fp;
char song[30],artist[30],album[30],year[4],comment[28],track;
char genre;
int i,j;
for(i=0;i<30;i++){
song[i]=0;
artist[i]=0;
album[i]=0;
}
for(j=0;j<28;j++){
comment[j]=0;
}
fflush(stdin);
printf("\nTitle: ");
gets(song);
printf("\nArtist: ");
gets(artist);
printf("\nAlbum: ");
gets(album);
printf("\nYear: ");
gets(year);
printf("\nComment: ");
gets(comment);
printf("\nTrack: ");
scanf("%d",&track);
printf("\nGenre: ");
scanf("%d",&genre);
fp=fopen(name,"rb+");
for(i=loc-125,j=0;i<loc-95,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(song[j],fp);
}
for(i=loc-95,j=0;i<loc-65,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(artist[j],fp);
}
for(i=loc-65,j=0;i<loc-35,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(album[j],fp);
}
for(i=loc-35,j=0;i<loc-31,j<4;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(year[j],fp);
}
for(i=loc-31,j=0;i<loc-3,j<28;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(comment[j],fp);
}
fseek(fp,loc-3,SEEK_SET);
fputc(00,fp);
fseek(fp,loc-2,SEEK_SET);
fputc(track,fp);
fseek(fp,loc-1,SEEK_SET);
fputc(genre,fp);
}

pls someone help me. :-(

Apr 11 '06 #1
4 1880
Sudip wrote:
I'm new in c programming. I am writing a program which reads the ID3 V1
tag from a mp3 file and edits it. But everytime i try to take inputs ,
the first character of my album contains 0. So, it doesn't write
anything at the start of album field. So, winamp cannot recognize the
album name. Can someone pls help me? :-(
[snip code with gets() and no error-checking]
pls someone help me. :-(


Hmmmmm ... "the first character of my album contains 0";

do you mean it contains 0 before or after you change it?
if it's before you change it I see no problem;
if it's after you change it, then simply change it to something other
than 0.

pseudo-code follows:

/* before you update the file, do */
if (album[0] == 0) {
album[0] = SOMETHING_ELSE;
}
/* now update the file */

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Apr 11 '06 #2
Ο/Η Sudip *γραψε:
I'm new in c programming. I am writing a program which reads the ID3 V1
tag from a mp3 file and edits it. But everytime i try to take inputs ,
the first character of my album contains 0.
Have you tried to print out the string stored in album[]? If what you
say is true, it is an empty string.
So, it doesn't write
anything at the start of album field. So, winamp cannot recognize the
album name. Can someone pls help me? :-(

The code for tag input and edit is:

void edittag(long loc,char name[]){
FILE *fp;
char song[30],artist[30],album[30],year[4],comment[28],track;
char genre;
int i,j;
for(i=0;i<30;i++){
song[i]=0;
artist[i]=0;
album[i]=0;
}
for(j=0;j<28;j++){
comment[j]=0;
}
This is not necessary as you store strings in the above arrays later
on. gets() will null-terminate the strings.
fflush(stdin);
This is non-standard, fflush() works on output streams. If you want to
eat up the rest of stdin you should look for a function called
flushln() which has been published here often. It looks like this:

int flushln(FILE *f)
{
int ch;
while ((EOF != (ch = fgetc(f))) && ('\n' != ch)) ;
return ch;
}
printf("\nTitle: ");
gets(song);
You should avoid using gets() because it can lead to buffer overruns,
consider fgets() instead.
printf("\nArtist: ");
stdout is probably line-buffered so you should use something:
fflush(stdout) after this call.
gets(artist);
printf("\nAlbum: ");
gets(album);
printf("\nYear: ");
gets(year);
printf("\nComment: ");
gets(comment);
printf("\nTrack: ");
scanf("%d",&track);
Consider the return value from scanf() and remember that you have at
least one newline character left in stdin. You should possibly use
flushln() after this call to scanf() to flush the stdin.
printf("\nGenre: ");
scanf("%d",&genre);
Same as above.
fp=fopen(name,"rb+");
Check the return value from fopen(), it could fail.
for(i=loc-125,j=0;i<loc-95,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(song[j],fp);
}
for(i=loc-95,j=0;i<loc-65,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(artist[j],fp);
}
for(i=loc-65,j=0;i<loc-35,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(album[j],fp);
}
for(i=loc-35,j=0;i<loc-31,j<4;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(year[j],fp);
}
for(i=loc-31,j=0;i<loc-3,j<28;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(comment[j],fp);
}
fseek(fp,loc-3,SEEK_SET);
fputc(00,fp);
fseek(fp,loc-2,SEEK_SET);
fputc(track,fp);
fseek(fp,loc-1,SEEK_SET);
fputc(genre,fp);
}

pls someone help me. :-(


Apr 11 '06 #3
Sudip wrote:

I'm new in c programming. I am writing a program which reads the ID3 V1
tag from a mp3 file and edits it. But everytime i try to take inputs ,
the first character of my album contains 0. So, it doesn't write
anything at the start of album field. So, winamp cannot recognize the
album name. Can someone pls help me? :-(

The code for tag input and edit is:

void edittag(long loc,char name[]){
FILE *fp;
char song[30],artist[30],album[30],year[4],comment[28],track;
char genre;
int i,j;
for(i=0;i<30;i++){
song[i]=0;
artist[i]=0;
album[i]=0;
}
for(j=0;j<28;j++){
comment[j]=0;
}
fflush(stdin);
printf("\nTitle: ");
gets(song);


You already have at least two fatal errors. fflush only functions
on output files, applying it to input files results in undefined
behaviour. It is also impossible to use gets() safely. You could
use fgets(), or my replacement for gets, ggets(), which is
available at:

<http://cbfalconer.home.att.net/download/ggets.zip>

as portable standard C source.

Since you are posting from the foully broken google interface to
usenet, read my sig and the referenced URLs before posting again,
or replying. Google is NOT usenet.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Apr 11 '06 #4
On 11 Apr 2006 02:35:40 -0700, "Sudip" <su*******@gmail.com> wrote:
I'm new in c programming. I am writing a program which reads the ID3 V1
tag from a mp3 file and edits it. But everytime i try to take inputs ,
the first character of my album contains 0. So, it doesn't write
anything at the start of album field. So, winamp cannot recognize the
album name. Can someone pls help me? :-(

The code for tag input and edit is:

void edittag(long loc,char name[]){
FILE *fp;
char song[30],artist[30],album[30],year[4],comment[28],track;
char genre;
int i,j;
for(i=0;i<30;i++){
song[i]=0;
artist[i]=0;
album[i]=0;
}
for(j=0;j<28;j++){
comment[j]=0;
}
fflush(stdin);
fflush is not defined for input streams, only output.
printf("\nTitle: ");
gets(song);
gets() can lead to buffer overflow.
printf("\nArtist: ");
gets(artist);
printf("\nAlbum: ");
gets(album);
printf("\nYear: ");
gets(year);
printf("\nComment: ");
gets(comment);
printf("\nTrack: ");
scanf("%d",&track);
%d tells scanf that the corresponding argument is an int*. You
provided a char*. Lie to the compiler and invoke undefined behavior.
You are overwriting memory.
printf("\nGenre: ");
scanf("%d",&genre);
Ditto.
fp=fopen(name,"rb+");
for(i=loc-125,j=0;i<loc-95,j<30;i++,j++){
The two relational expressions in the second clause do not do what you
think. The first is evaluated and then discarded. Then the second is
evaluated and that value is the "result" of the clause. Did you mean
&& instead of comma. Besides, one of them is redundant.
fseek(fp,i,SEEK_SET);
Why do you feel the need to seek to the next sequential position?
Wouldn't one seek before the for loop be sufficient?
fputc(song[j],fp);
}
for(i=loc-95,j=0;i<loc-65,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(artist[j],fp);
}
for(i=loc-65,j=0;i<loc-35,j<30;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(album[j],fp);
}
for(i=loc-35,j=0;i<loc-31,j<4;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(year[j],fp);
}
for(i=loc-31,j=0;i<loc-3,j<28;i++,j++){
fseek(fp,i,SEEK_SET);
fputc(comment[j],fp);
}
fseek(fp,loc-3,SEEK_SET);
fputc(00,fp);
fseek(fp,loc-2,SEEK_SET);
fputc(track,fp);
fseek(fp,loc-1,SEEK_SET);
fputc(genre,fp);
}

pls someone help me. :-(

Remove del for email
Apr 12 '06 #5

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

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
5
by: jbruno4000 | last post by:
I'm having 2 problems and hope you can help: Fist Problem: Please see the code segment bellow. For this application I need to access an input file and also an output file, however, when I include...
10
by: Chih-Hsu Yen | last post by:
I encountered a strange problem about switch-case statement. switch(cmd) { case 1: statements; break; case 2: statements; break; ... .... case 11: S1; S2; S3; statements;
4
by: Dino Buljubasic | last post by:
Hi, I am using a function to hash a string value: public string generateMD5Hash(string input) { MD5 md5Provider; // MD5 provider instance // generate byte code for input byte inputData =...
1
by: John | last post by:
Hi I have two forms on my page. Both use javascript to validate input before submission. Problem is that first form does the validation fine but the second form gets submitted without any...
3
by: Ralph | last post by:
Hi I have small function to generate my form controls: function buildInput(sType, vValue, vId, sName, sLabel){ var oInput = null; var oLabel = document.createElement('label'); var oCont =...
12
blackstormdragon
by: blackstormdragon | last post by:
Im having trouble with my classList variable. It's a dynamic array of strings used to store the names of the classes(my program ask for students name, number of classes, then a list of the classes). ...
3
by: judge82 | last post by:
Please I need help with this so bad. I have been struggling with it for 2weeks now. on line 206, I what to create a link that will direct you to the detail of the chosen items, like in the...
8
by: DL | last post by:
The following line is dynamically generated, which works fine at least with IE7 but what I want more out of it is to disable this button upon click, so, pls see next line of my attempt to use CSS...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.