Hello every one!Please help me!!
I am new to C programming.I wrote a programe to copy lines one by one of a file to an array.But it cant compile.I cant understand the error code also.Please help me!
here is my code.
In your haste to post your poorly formatted code, you may have missed the opportunity to read the sticky notes at the top of the forum page. In particular, how to ask questions properly and how to format code using code tags.
1) you are not returning a value - main() returns an int.
2) your strdup() and sprintf() function calls are all wrong. Have you studied how these functions work? With strdup(), you are trying to assign the return string to a character!
3) sprintf() parameters are wrong. This function is similar to printf() except that the output is stored in the character array. I'm not sure why you even want to do this considering that you've called strdup() in the previous line. It's either one or the other.
4) I think your logic is a "bit off". It seems like you want to read a line from your file and assign each line to an element of your array - an array of strings. If this is the case, then your declaration for c needs to be an array of pointer to char - char *c. And then you'll have to allocate memory for each pointer as well before pointing it anywhere.
Thanks Yellow Snow for great advices.Finally I was able to solve the problem.I am new to this forum.Very sorry for the mess.The mistake was at array declaration it should be like "char *c"
and need to allocate memory.Again and again thanks very mush for all.
public class GrossmontBank
//class variables (global - accessible throughout this class)
//scanner object to be used throughout
private static Scanner input = new Scanner(System.in);