GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Oct-2004, 23:09
if13121 if13121 is offline
New Member
 
Join Date: Oct 2004
Posts: 27
if13121 is on a distinguished road
Unhappy

very simple c question


Dear All. I'm completely newbie to c. I make function to copy string and function to get its length but i doesn't work. Please help me. Whats wrong with this program:

CPP / C++ / C Code:
  typedef int IdxType;
  typedef struct {
	char TKata[20];
	int len;
  }kata;

  typedef struct
  {
	int DD;
	int MM;
	int YYYY;
  }date;
   typedef struct 
  {     
  	int TSize[100];              
	date TDate[100];		
  	kata TFile[100];    		
	int NBFile;            
  }  Tab;

void PrintTable(Tab T);
int NbElmt(Tab T);
void SetFile(Tab T, IdxType i,kata v);
void CopyKata ( kata  Tin , kata * Tout);
void getLen(kata L);

int main()
{
	date L;
 	Tab T;
	kata Input,v,aku;
  	T.TDate[1].DD   = 0;	T.TDate[1].MM   = 0;	T.TDate[1].YYYY = 0;
	T.TDate[2].DD   = 0;	T.TDate[2].MM   = 0;	T.TDate[2].YYYY = 0;
	Input.TKata[1] = 't';	Input.TKata[2] = '.';	Input.TKata[3] = 't';
	Input.TKata[4] = 'x';	Input.TKata[5] = 't';	Input.len = 5;
	T.TSize[1]=1;	T.TSize[2]=1;
	T.NBFile = 2;
	CopyKata(Input,&(T.TFile[1]));
	CopyKata(T.TFile[1],&(T.TFile[2]));
	PrintTable(T);
	printf("insert new file to  TOC\n");
	printf("Input file name: \n"); 
	scanf("%s",v.TKata);
	getLen(v);
	printf("file name length: %d\n",v.len);
	T.TDate[3].DD   = 0; T.TDate[3].MM   = 0; T.TDate[3].YYYY = 0;
	SetFile(T,3,v);
	T.NBFile = 3;
	T.TSize[3]=3;
	PrintTable(T);
	return 0;
}

void PrintTable(Tab T)
 {
    int i,j;
    printf("\nTable of Content\n");
   
    if (NbElmt(T) != 0 ) 
    {
    
    for (i = 1; i < (NbElmt(T)+1);i++)
      {
	 //print  TKata
         for (j = 1; j < (T.TFile[i].len + 1);j++)
         {
         printf("%c",T.TFile[i].TKata[j]);
         }
         printf("   %d",T.TSize[i]);
	 printf("   %d-"  ,T.TDate[i].DD);
	 printf("%d-"  ,T.TDate[i].MM);
	 printf("%d\n" ,T.TDate[i].YYYY);
      }
    }
    else 
    {printf("The table is empty\n");}
  }

int NbElmt(Tab T)
{
     return(T.NBFile);
}

 void SetFile(Tab T, IdxType i,kata v)
 {  	CopyKata(v,&(T.TFile[i]));
 }
  
void getLen(kata L)
{	
	int i=0;
	while(L.TKata[i] != '\0')
	{i++;}
	L.len = i-1;	  	
}

void CopyKata ( kata  Tin , kata *Tout)
{	
	int i;
	(*Tout).len = Tin.len;
	for (i = 1; i < (Tin.len +1);i++)
	{
	   (*Tout).TKata[i] = (Tin).TKata[i];
	}
	
}
Last edited by LuciWiz : 18-Oct-2004 at 01:48. Reason: Please insert your C code between [c] [/c] tags
  #2  
Old 18-Oct-2004, 00:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by if13121
Dear All. I'm completely newbie to c. I make function to copy string and function to get its length but i doesn't work. Please help me. Whats wrong with this program:
What's wrong? Well,
1) You didn't use code tags so your code can be read. Doesn't anyone new read the stickys?
2) Arrays start with an index of 0 so your first element in your input string input.Kata[0] is undefined. Yes you compensated by starting at 1 in your loop but when you try to access input.Kata[20] your program may crash. This will also have a negntive affect on the filename you input.
3) You didn't tell us what's wrong with it. It seems to be fine up to the first PrintTable() call.

Be more specific and explain
a) what you are trying to accomplish with this program
b) what it should do
c) what it is not doing
d) where you think the problem is
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New to this forum...just a little question... rune hunter C++ Forum 4 16-Oct-2004 09:33
Denying directory listing and htaccess question meet_raman Apache Web Server Forum 11 01-Jul-2004 10:20
question of practice magiccreative C++ Forum 1 06-Feb-2004 07:17
Simple Question regarding installing Apache 2.0 macjoubert Apache Web Server Forum 0 13-Nov-2003 11:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.