abhimanipal 91 Master Poster

Print the value of coming in from ch

abhimanipal 91 Master Poster

What part of file handling is confusing ?

There are 4 basic operations
1. Read --> Read the contents of a file . Use fread for this
2. Write --> Write to a file . Open the file is write mode and then use fwrite for this.
3. Append --> Append to end of file. Open the file in append mode and then use fwrite
4. seek --> When you use fopen to open a file the file pointer usually points to the start of the file. But if you want to update the contents of a file you have to move the file pointer away from the start. Use fseek for this

Try googling for these functions . You should find lots of sample code / tutorials

abhimanipal 91 Master Poster

Can you explain the purpose of each argument in the movePlayer function ?
Also what is the function getTitle supposed to return ?

abhimanipal 91 Master Poster

In your code the declaration of the pointer account_array is fine.

char (account_array[size];

I guess you meant

char *account_array[size];
abhimanipal 91 Master Poster

I ran the code you had provided and it gave an error

$ ./test
ping: invalid option -- 'D'
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
[-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
[-M mtu discovery hint] [-S sndbuf]
[ -T timestamp option ] [ -Q tos ] [hop1 ...] destination
obtained the following seed: 0.0
$

abhimanipal 91 Master Poster

Also how about clearing the content in the namelist array before using the add function

for(int i=0;i<size;i++)
{
   for(int j=0;j<namelist[i].length;j++)
              namelist[i][j] = '\0';
}

Maybe overkill but wont hurt

abhimanipal 91 Master Poster

Yes ...

abhimanipal 91 Master Poster

In your while loop (lines 36 - 39) you are not checking to see if you hit NULL or not

WHen you do current = current->next check to see current->next is not equal to NULL

abhimanipal 91 Master Poster

What kind of error are you getting ?
Did you include all the header files ?

abhimanipal 91 Master Poster

If you want to use pointers to pass a 2-D array write your code like this

void
printStuff(int* a,int rows,int cols)
{
    int i=0,j=0;
    
    for(i=0;i<rows;i++)
    {
          for(j=0;j<cols;j++)
               printf("%d\t",a[(i*rows) + j]);
    }
}

int
main(int argc, char *argv[])
{
         int a[3][3];
         int i=0,j=0,count=0;
         
         for(i=0;i<3;i++)
         {
               for(j=0;j<3;j++)
                     a[i][j] = count++;
         }
         
         printStuff(&a[0][0],3,3);
                  
         return 0;
}
abhimanipal 91 Master Poster

Is the format of the input file pre defined or can it change
If the input file format is not fixed then this is a hard problem

abhimanipal 91 Master Poster

Use the code tag..
After you have pasted your code into the little box, select all the code and then click on the (CODE)
Preview your post to see if the formatting has come out correctly or not

abhimanipal 91 Master Poster

I am not so sure if that was the only reason for your problem . Try running this piece of code

int main()
{
    char *arr = "ls -l";
    char *pch = NULL;
    
    printf("%s\n",arr);
    pch = strtok(arr," ");
    printf("%s\n",pch);

    return 0;
}

This will give you a seg fault. The reason being when you write
char *arr the memory for this is in the code segment of the program. You are not allowed to modify anything that is written in the code segement
When you issue the strtok command, you are telling the program to replace each instance of " " with '\0' or in other words you are modifying data written in the code segment.
The system does not like this and hence crashes on you

abhimanipal 91 Master Poster

It appears line 6 needs to be changed as well, to the following:

int *nums = new int[SIZE];

It seems windows doesn't like to initialize such large arrays the way you were using, but this way will work fine.

This is a C forum ..... the operator new wont work with a C compiler

abhimanipal 91 Master Poster

Just think for a moment what you are doing.

In line 2 you are asking the computer to store a string in a char. So if I give the input as ABCDEFGH it will be stored in a char
Then in line 3 you are telling the computer to store that char in an array .

Is this what you really want ?

abhimanipal 91 Master Poster

You could pass the input string as a command line argument

int main(int argc,char* argv[])
{
   printf("%s\n",argv[1]);
}

and then when you execute the program, you execute it like this ./test input string

I seriously think you need to read C from a book.

abhimanipal 91 Master Poster

Do you know what is a char array ?

abhimanipal 91 Master Poster

Or some thing of this sort

int main()
{
    int a,b,c;
    scanf("%d\n%d\n%d",&a,&b,&c);
    
    printf("A is %d\nB is %d\nC is %d\n",a,b,c);
    return 1;
}

PS: Using scanf is a bad idea. The sooner you shift to fgets the better

abhimanipal 91 Master Poster

An easy way would be to execute the ls command in your program...

abhimanipal 91 Master Poster

In one of my previous posts I told you to google for the syntax of malloc. Did you do that ?Both of your questions will be answered.

I meant where in the main program are you opening and closing the files ?Also is it necessary for you to use processes or can you use threads as well ?

abhimanipal 91 Master Poster

fgets can be used to input integers as well. We convert the string to integer using atoi.

abhimanipal 91 Master Poster

In addition to what has been suggested above, I would advise you to run the for loop from 0.....strlen(word) as opposed to 0....20

abhimanipal 91 Master Poster

The problem is in the winsock library. When you call functions from that library, you get linker error.
Write a simple 2-3 line code calling a function from winsock library to check if your library is installed correctly

abhimanipal 91 Master Poster

find return a pointer to the location of the first =.
Then copy the contents from after the = till end of string into a temporary buffer
Return the temporary buffer

abhimanipal 91 Master Poster

Is that what would cause these errors for me?

You never know until you try

abhimanipal 91 Master Poster

If you make the array global you do not need to pass it to any function. All functions have complete access to all global variables. So if you declare the array as global your approach will be something of this sort

int arr[10][10];

void func()
{
// Set/ get data into the array arr
}
int main()
{
  func();
}

But making a variable global is frowned upon in the industry as the variable can be modified from any where. So the other option is to pass the array by pointer (reference)

void func(int* arr)
{
   // The variable arr contains the address of the first element of the array
}

int main()
{
  int arr[10][10];
  func(&arr[0][0]);
}
abhimanipal 91 Master Poster

Dude there are many mistakes in your program

Hi.I write a program in C for my microcontroller(PIC 18F452) but
faced to a problem that related only to C language and that is;
as you can see in my Main program and the two Functions I want to
pass an array of ; " int adcvalmax[8] " which got valued in the Function;
" int CHS_Read(int adcvalmax[8]) ", between " Main " program and
Function; void Display_AdcX(int adcvalmax[8] ) for processing.
But I do not know if my "Main & Functions" are right or not?

Here are the descriptions of my Functions and Main program;

1.int CHS_Read(int adcvalmax[8]); Reading input values by analog to digital module of the PIC18F452 and save the results in the array
" adcvalmax[m] ".

2.void Display_AdcX(int adcvalmax[8] ) ;get the array
" adcvalmax[m] "and by using it display its value on LCD.

3.In the Main program I call Function; " void Display_AdcX(int adcvalmax[8] ) " as; Display_AdcX( adcvalmax[] ); .

Would you please help me and tell me if my program and functions are right or not?And what is/are wrong in my program?

Thanks,

unsigned char ch0=0,ch1=0;
int t0=0,t1=0;
char *tc;
// This is not allowed. I guess what you want to do is declare an array of 8 and initialize all the elements to 0. You want some thing of this sort int arr[8]={0,0,0,0,0,0,0,0};
int adcvalmax[8]=0;

#define stepsize  98
int  interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
   int …
WaltP commented: Such a helpful post. I was wondering why he asked for help! -2
abhimanipal 91 Master Poster

Is this code all there is or is there more to it

abhimanipal 91 Master Poster

I dont know if this is a stupid question, but if the language is not English then how do you expect to take user input ?


Well I got the answer for my question.. Apparently key boards/ emulation software for non english languages are a common thing

abhimanipal 91 Master Poster

Get started with you HW
Post your progress and a specific question
If you just post the question that you got for an assignment without showing your efforts then you will be ignored

Rashakil Fol commented: seems like a perfectly reasonable question to me. -1
abhimanipal 91 Master Poster

Quick question. Have you ever included files before ? If no then I think
for some reason the header files in the main class are not getting included. That is why, when you call the constructor of the classes defined in those files you are getting an error.

abhimanipal 91 Master Poster

You are passing the arrays by value. The changes made to these arrays will be local to the function.
Pass by pointer or use global variables

Dave Sinkula commented: Arrays can't be passed by value the way you imply. -2
abhimanipal 91 Master Poster

If you have an array of 4 characters, then you have 32 bytes...
Will this work for your application ?

abhimanipal 91 Master Poster

You might want to try the function

gettimeoftheday()

PS I am not sure of the arguments

Dave Sinkula commented: Hey! Wow! This post is almost entirely useless! -2
abhimanipal 91 Master Poster

For printing the string the normal way (unreversed) you can use

printf("%s\n,name_of_string)

WaltP commented: And how does this comment help with printing the string backwards? -2
abhimanipal 91 Master Poster

Try coders for hire, students of fortune.
They may be more amenable to your request

abhimanipal 91 Master Poster

One solution could be you could insert a '\0' /-1/some other invalid value after you are done inserting the numbers. Then in the function you can loop till you hit that invalid value