Dynamic Memory Allocation - c

I'm having trouble dynamically allocating memory for an array. I've been debugging for hours, any pointers?
I posted the rest of the code. It is simply supposed to exchange the swap the first row with the second, and the third with the forth. I am getting strange results like:
Enter string: hello
Enter string: how are you
Enter string: i'm good thanks
Enter string: bye
Enter string: bai
Enter string: xx
=========================
how are you
!i'm good thanks
hello
!how are you
bye
!bai
i'm good thanks
!bye
bai
!xx
int count = 0;
char *lines[MAX_LINES];
char *tmp[50];
printf("Enter string: ");
fgets(tmp, 50, stdin);
lines[count] = (char *) malloc((strlen(tmp)+1) * sizeof(char));
strcpy(lines[count], tmp);
while(strcmp("xx\n", lines[count])){
count++;
printf("Enter string: ");
fgets(tmp, 50, stdin);
lines[count] = (char *) malloc((strlen(tmp)+1)* sizeof(char));
strcpy(lines[count], tmp);
}
void exchange(char * records[])
{
char * temp;
temp = records[0];
records[0] = records[1];
records[1] = temp;
temp = records[2];
records[2] = records[3];
records[3] = temp;
}
void printArray(char * inputs[], int row, int col)
{
int i, j;
for(i = 0; i < row; i++){
for(j = 0; j < col; j++){
printf("%c", inputs[i][j]);
}
}
}

This code seems to work:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum { MAX_LINES = 50 };
static void printArray(char *inputs[], int rows);
static int readLine(char *buffer, size_t buflen);
int main(void)
{
int count = 0;
char *lines[MAX_LINES];
char tmp[50];
for (count = 0; count < MAX_LINES; count++)
{
if (readLine(tmp, sizeof(tmp)) == EOF)
break;
lines[count] = (char *) malloc((strlen(tmp)+1)* sizeof(char));
if (lines[count] == 0)
break;
strcpy(lines[count], tmp);
}
putchar('\n');
printArray(lines, count);
return(0);
}
static int read_line(char *buffer, size_t buflen)
{
printf("Enter string: ");
if (fgets(buffer, buflen, stdin) == 0 || strcmp("xx\n", buffer) == 0)
return EOF;
return 0;
}
static void printArray(char *inputs[], int rows)
{
for (int i = 0; i < rows; i++)
printf("%d: %s", i, inputs[i]);
}
Sample run 1 (using EOF):
$ ./rl
Enter string: Abyssinia
Enter string: Wimbledon Common
Enter string: ^D
0: Abyssinia
1: Wimbledon Common
$
Sample run 2 (using 'xx'):
$ ./rl
Enter string: Abyssinia
Enter string: Wimbledon Common
Enter string: Strawberry Lemonade
Enter string: xx
0: Abyssinia
1: Wimbledon Common
2: Strawberry Lemonade
$
What's different? I fixed the type on tmp as noted in a comment. I created a function readLine() to manage the prompt and read and compare with "xx\n" process to avoid repetition. I avoided using strdup() but do check that malloc() succeeds before using the pointer returned. I ensure that there are not too many lines read in (the for loop). The printArray() code only takes the number of rows because the strings are of varying length. I removed the exchange() function since it was not being used and I couldn't see how it was supposed to be used. The code is complete and compilable (so it is an SSCCE — Short, Self-Contained, Correct Example).

Related

C Input scanf() confusion

I want to use scanf() to read the input string.
If the input of printf("Enter start word: "); is the symbol #, it will not execute the next printf("Enter end word: "); command, and if the input is a word, then it will execute the next command. But I don't know how to determine whether the input is a symbol or a word.
Whatever I input, it still executes printf("Enter end word: ");
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#define MAX_WORD_LENGTH 32
#define FORMAT_STRING "%31s"
#define VERY_HIGH_VALUE 999999
char **InputWords(int *n, char *start, char *end) {
printf("Enter a number: ");
scanf("%d", n); // the number of the input words
char **words = malloc(sizeof(char *) * *n);
assert(words != NULL);
for (int i = 0; i < *n; i++) {
// allocate memory for the length of each input word
words[i] = malloc(sizeof(char) * MAX_WORD_LENGTH);
assert(words[i] != NULL);
printf("Enter a word: ");
scanf(FORMAT_STRING, words[i]);
}
printf("Enter start word: ");
if (scanf("%s", start) == 1) {
printf("Enter end word: ");
scanf("%s", end);
};
printf("\n");
printf("%d, %s, %s", *n, start, end);
return words;
}
int main(void) {
int n;
char start, end; //the start/end word, which is not necessary in stage 1-4
char **words = InputWords(&n, &start, &end); //create an array to store all input words
return 0;
}
Moreover, when I add the code printf("%d", n); at the end of the function, the value of n becomes 0, although my input n is other number.
When I add printf("%d, %s, %s", *n, start, end); at the last, the output shows
Enter a number: 3
Enter a word: bad
Enter a word: ban
Enter a word: dad
Enter start word: bad
Enter end word: ban
110, an, ban
But in my input, the n = 3, start = ban and end = ban
There are multiple problems in the code:
you pass the addresses of single char variables to InputWords instead of arrays of sufficient length. Reading a string into single char variables causes undefined behavior because scanf() will store at least 2 bytes into the destination array.
you should always specify the maximum number of characters to store into the destination arrays for scanf("%s", ...)
to prevent reading the end word you can simply test if the word read for start starts with a #:
*end = *start = '\0';
if (scanf("%31s", start) == 1 && *start != '#') {
printf("Enter end word: ");
scanf("%31s", end);
}
Here is a modified version:
#include <stdio.h>
#include <stdlib.h>
#define MAX_WORD_LENGTH 31
#define FORMAT_STRING "%31s"
char **InputWords(int *np, char *start, char *end) {
int n = 0;
*np = 0;
*start = *end = '\0';
printf("Enter a number: ");
if (scanf("%d", &n) != 1) // the number of the input words
return NULL;
char **words = calloc(sizeof(char *), n);
assert(words != NULL);
for (int i = 0; i < n; i++) {
// allocate memory for the length of each input word
words[i] = calloc(sizeof(char), MAX_WORD_LENGTH + 1);
assert(words[i] != NULL);
printf("Enter a word: ");
if (scanf(FORMAT_STRING, words[i]) != 1) {
/* invalid input or premature end of file */
while (i --> 0) {
free(words[i]);
}
free(words);
return NULL;
}
}
printf("Enter start word: ");
if (scanf(FORMAT_STRING, start) == 1 && *start != '#') {
printf("Enter end word: ");
scanf(FORMAT_STRING, end);
}
printf("\n");
printf("%d, %s, %s\n", n, start, end);
*np = n;
return words;
}
int main() {
int n;
char start[MAX_WORD_LENGTH + 1]; // the start word
char end[MAX_WORD_LENGTH + 1]; // the end word, which is not necessary in stage 1-4
char **words = InputWords(&n, start, end); //create an array to store all input words
return 0;
}
Try this and tell me what doesn't work now:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define FORMAT_STRING "%31s"
#define MAX_WORD_LENGTH 32
char **InputWords(int *n, char *start, char *end) {
printf("Enter a number: ");
scanf("%d", n); // the number of the input words
char **words = malloc((*n) * sizeof(*words));
assert(words);
for (int i = 0; i < *n; i++) {
// allocate memory for the length of each input word
words[i] = malloc(MAX_WORD_LENGTH);
assert(words[i]);
printf("Enter a word: ");
scanf(FORMAT_STRING, words[i]);
}
printf("Enter start word: ");
if (scanf(FORMAT_STRING, start) == 1) {
printf("Enter end word: ");
scanf(FORMAT_STRING, end);
};
printf("\n%d, %s, %s", *n, start, end);
return words;
}
int main(void){
int n;
char start[MAX_WORD_LENGTH];
char end[MAX_WORD_LENGTH];
char **words = InputWords(&n, start, end); //create an array to store all input words
// silence unused variables
(void) n;
(void) start;
(void) end;
return 0;
}

C program function to replace one word with another

I am very confused to create a function which will print a string and ask user to enter two numbers and then function will replace those number of words with one another.
I have added the image below as sample.
enter image description here
This is my homework, I have created other 3 functions, but don't really get this one.
Could somebody please help me how can I convert the words into numbers and then replace those number of words with one another.
This is my program it can break the string into words but how can i replace position of words.
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100];
char newString[10][10];
int i,j,ctr;
printf("\n\n Split string by space into words :\n");
printf("---------------------------------------\n");
printf(" Input a string : ");
fgets(str1, sizeof str1, stdin);
j=0; ctr=0;
for(i=0;i<=(strlen(str1));i++)
{
// if space or NULL found, assign NULL into newString[ctr]
if(str1[i]==' '||str1[i]=='\0')
{
newString[ctr][j]='\0';
ctr++; //for next word
j=0; //for next word, init index to 0
}
else
{
newString[ctr][j]=str1[i];
j++;
}
}
printf("\n Strings or words after split by space are :\n");
for(i=0;i < ctr;i++)
printf(" %s\n",newString[i]);
return 0;
}
Seems to me that you are doing pretty good so far (your code can't handle comma but you can add that later). So let's assume that your newString actually contains the individual words.
So your next step is to construct a new string str2 from the individual words you have in newString. While you do that you can simply swap the two words of interest. To build the new string the strcat function could be helpful.
The code below is not fully correct but it may give you some ideas for getting on with your homework:
int lowest_index_to_swap = some_number
int highest_index_to_swap = some_higher_number
char str2[100] = "";
for (i=0; i<number_of_words_found; ++i)
{
if (i == lowest_index_to_swap)
strcat(str2, newString[highest_index_to_swap];
else if (i == highest_index_to_swap)
strcat(str2, newString[lowest_index_to_swap];
else
strcat(str2, newString[i];
strcat(str2, " ";
}
Here is code snippet what I tried in my local server based on your input in image.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100
#define WORDLEN 20
int main() {
int place_1, place_2, count = 0, i, k =0;
char str[] = "Hi, welcome to C programming";
char **words = (char **)malloc(sizeof(char *)*SIZE);
if(!words){
printf("malloc of words failed!\n");
exit(1);
}
char *temp = (char *)malloc(sizeof(char)*WORDLEN);
if(!temp){
printf("malloc of temp failed!\n");
exit(1);
}
for(i = 0; str[i] != '\0'; count++){
words[count] = (char *)malloc(sizeof(char)*WORDLEN);
if(!words[count]){
printf("malloc of words[%d] failed!\n", count);
exit(1);
}
sscanf(str+i, "%s", words[count]);
i += 1+strlen(words[count]);
printf("%d %s %d\n", count, words[count], i);
}
printf("Enter the word places to replace: ");
if(scanf("%d %d", &place_1, &place_2) < 2){
printf("scanf failed!\n");
exit(1);
}
temp = words[place_1 - 1];
words[place_1 - 1] = words[place_2 - 1];
words[place_2 - 1] = temp;
for(i = 0; i < count; i++){
sprintf(str+k, "%s ", words[i]);
k += 1+strlen(words[i]);
}
printf("str: %s\n", str);
free(temp);
for(i = 0; i < count; i++){
free(words[i]);
}
free(words);
}
Hope it helps.

geting input of string and character in a loop on c

Actually recently i found a problem where i need to count occurrence a given(by oj) char in a given string(with test case).So i write this code but output is not as i desired.I'm a beginner so i'll be greatly thankful for any kind of instructive advice or help.THANK YOU.
#include<stdio.h>
#include<string.h>
int main ()
{
int ara [123];
char s[1000];
int l, j, i, len;
char c;
scanf ("%d\n", &l);
while (l >= 0){
for (i = 65; i <= 122; i++)
{
ara[i] = 0;
}
fgets(s, 1000, stdin);
len = strlen(s);
for (i = 0;i <= len; i++)
{
ara[s[i]]++;
}
scanf(" %c\n", &c);
j = c;
printf("count : %d\n", ara[j]);
l--;
}
return 0;
}
The problem is that scanf is leaving a newline in the input to be read as the target sentence.
You can get around this by using fgets and sscanf instead. I also added some cues to make it easier to know what is expected.
#include <stdio.h>
#include <string.h>
int main (void)
{
int ara [128]; // increased array size
char s[1000];
char t[10];
int l, j, i, len;
char c;
printf("Enter how many loops:\n");
fgets(t, sizeof t, stdin); // replace scanf
sscanf (t, "%d\n", &l); // with sscanf
while (l > 0){ // changed end test
for (i = 'A'; i <= 'z'; i++) // replaced magic numbers
{
ara[i] = 0;
}
printf("Enter the string:\n");
fgets(s, sizeof s, stdin);
len = strlen(s);
for (i = 0;i <= len; i++)
{
ara[s[i]]++;
}
printf("Enter the letter:\n");
fgets(t, sizeof t, stdin); // replace scanf
sscanf (t, "%c\n", &c); // with sscanf
j = c;
printf("count : %d\n", ara[j]);
l--;
}
return 0;
}
Program session
Enter how many loops:
2
Enter the string:
one two three four
Enter the letter:
o
count : 3
Enter the string:
three seven
Enter the letter:
e
count : 4
Note that ideally, you should also check the function return values from fgets and sscanf.

get name and marks of students with structs

I've got a task to get no. of students, get their name and marks and output the students which has average over 85.
The problem: After I enter blabla 99 98 95 90, I don't get the appropriate message. what I get is just some kind random of average instead. I mean, Print_One() isn't executed after that input. (Failing to print the average above 85)
Here's my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef struct {
char *name;
int marks[4];
float avg;
} student;
student *Create_Class(int);
void Avg_Mark(student*);
void Print_One(student*);
void exStudents(student *s, int size);
int main() {
int size, i;
student *arr;
printf("\nEnter the number of students: \n");
scanf("%d", &size);
arr = Create_Class(size);
exStudents(arr, size);
for (i = 0; i < size; i++)
free(arr[i].name);
free(arr);
getch();
}
student *Create_Class(int size) {
int i, j;
int idStud, nameStud, markStud;
student *classStudent;
classStudent = (student*)malloc(size * sizeof(student));
for (i = 0; i < size; i++) {
classStudent[i].name = (char*)malloc(51 * sizeof(char));
int numOfmarks = 4;
int sizeOfName;
printf("Please enter your name: \n");
flushall();
gets(classStudent[i].name);
sizeOfName = strlen(classStudent[i].name);
/*
if (classStudent[i].name > 50) {
classStudent[i].name = realloc(classStudent[i].name, 51);
classStudent[i].name[51] = '\0';
} else {
classStudent[i].name = realloc(classStudent[i].name, sizeOfName + 1);
}
*/
printf("Please enter 4 marks: ");
for (j = 0; j < numOfmarks; j++) {
scanf("%d", &classStudent[i].marks[j]);
}
Avg_Mark(&classStudent[i]);
}
return classStudent;
}
void Avg_Mark(student *s) {
int i, numOfMarks = 4, sum = 0;
for (i = 0; i < numOfMarks; i++) {
sum += s->marks[i];
}
s->avg = (sum / 4.0);
}
void Print_One(student *s) {
printf("The average of %s is %f", s->name, s->avg);
}
void exStudents(student *s, int size) {
int flag = 1;
while (size > 0) {
if (s->avg > 85) {
Print_One(s);
flag = 0;
}
s++;
size--;
}
if (flag)
printf("\n There're no students with above 85 average.");
}
If your input is like this:
1
blabla
99 98 95 90
The first newline after 1 is still in the input buffer when your program reaches get, so an empty line is read and then the scanfs will fail.
An easy fix could be to read the first number using this format:
scanf("%d ", &size);
// note ^ the space will consume the newline
But, as #chqrlie pointed out, "it will continue to read bytes from stdin until it sees one that is not whitespace. This will require the user to respond to the next question before the prompt is written."
A better idea is to read the name using another scanf, but limiting the maxium number of chars read to the allocated size and adding a space at the beginning of the format string to consume all pending whitespaces:
// read max 50 char till a newline and extract the rest of line without storing it
scanf(" %50[^\n]%*[^\n]", classStudent[i].name);
// ^^^ a space at the beginning will also consume trailing spaces or newline
It worked for me. All i did was using
_flushall();
instead of
flushall();

Why I can't input my name with gets?

Here's the part of my code:
Problem: It skips the input of "please enter your name" to "please enter your marks"
What I tried: flushall(); _flushall(); - which worked yesterday somehow, and trying to place these functions between printf,scanf..
student *Create_Class(int size) {
int i, j;
int idStud, nameStud, markStud;
student *classStudent;
classStudent = (student*)malloc(size * sizeof(student));
for (i = 0; i < size; i++) {
classStudent[i].name = (char*)malloc(51 * sizeof(char));
int numOfmarks = 4;
printf("Please enter your name: ");
gets(classStudent[i].name);
_flushall(); //tried _flushall() and it worked yesterday.. tried fflush(NULL) too.
printf("\nPlease enter 4 marks: ");
for (j = 0; j < numOfmarks; j++) {
scanf("%d", &classStudent[i].marks[j]);
}
Avg_Mark(&classStudent[i]);
}
return classStudent;
}
EDIT: (FULL CODE)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef struct {
char *name;
int marks[4];
float avg;
} student;
student *Create_Class(int);
void Avg_Mark(student*);
void Print_One(student*);
void exStudents(student *s, int size);
int main() {
int size, i;
student *arr;
printf("\nEnter the number of students: \n");
scanf("%d", &size);
arr = Create_Class(size);
exStudents(arr, size);
for (i = 0; i < size; i++)
free(arr[i].name);
free(arr);
getch();
}
student *Create_Class(int size) {
int i, j;
int idStud, nameStud, markStud;
student *classStudent;
classStudent = (student*)malloc(size * sizeof(student));
for (i = 0; i < size; i++) {
classStudent[i].name = (char*)malloc(51 * sizeof(char));
int numOfmarks = 4;
int sizeOfName;
printf("Please enter your name: \n");
_flushall();
fgets(classStudent[i].name,50,stdin);
sizeOfName = strlen(classStudent[i].name);
printf("Please enter 4 marks: ");
for (j = 0; j < numOfmarks; j++) {
scanf("%d", &classStudent[i].marks[j]);
}
Avg_Mark(&classStudent[i]);
}
return classStudent;
}
void Avg_Mark(student *s) {
int i, numOfMarks = 4, sum = 0;
for (i = 0; i < numOfMarks; i++) {
sum += s->marks[i];
}
s->avg = (sum / 4.0);
}
void Print_One(student *s) {
printf("The average of %s is %f", s->name, s->avg);
}
void exStudents(student *s, int size) {
int flag = 1;
while (size > 0) {
if (s->avg > 85) {
Print_One(s);
flag = 0;
}
s++;
size--;
}
if (flag)
printf("\n There're no students with above 85 average.");
}
As you have already been told in comments, the solution is to use a two-step approach: Read lines first, then scan these lines as appropriate. This reflects how users are going to answer your prompts, namely by providing the information and then hitting enter.
Here's a variant of your code which does that. I've also changed the main function, because it also used scanf and I've added a function to strip white space from the string input by fgets. (This function requires the <ctype.h> header.)
#include <ctype.h>
int main()
{
char line[80];
int size, i;
puts("Enter the number of students:");
if (fgets(line, sizeof(line), stdin) == NULL) exit(1);
if (sscanf(line, "%d", &size) == 1 && size > 0) {
student *arr = Create_Class(size);
exStudents(arr, size);
for (i = 0; i < size; i++) free(arr[i].name);
free(arr);
}
return 0;
}
/*
* strip white space from beginning and end of string
*/
char *strip(char *str)
{
size_t l = strlen(str);
while (l > 0 && isspace((unsigned char) str[l - 1])) l--;
str[l] = '\0';
while (isspace((unsigned char) *str)) str++;
return str;
}
/*
* Create students and prompt user for input
*/
student *Create_Class(int size)
{
int i;
student *classStudent = malloc(size * sizeof(student));
for (i = 0; i < size; i++) {
char line[80];
char *p;
int okay = 0;
puts("Please enter your name:");
if (fgets(line, sizeof(line), stdin) == NULL) exit(1);
p = strip(line);
classStudent[i].name = malloc(strlen(p) + 1);
strcpy(classStudent[i].name, p);
while (!okay) {
int j = 0;
okay = 1;
puts("Please enter 4 marks:");
if (fgets(line, sizeof(line), stdin) == NULL) exit(1);
p = line;
while (p && j < 4) {
char *tail;
int m = strtol(p, &tail, 10);
if (p == tail) break;
if (m < 1 || m > 100) {
puts("Illegal mark.");
okay = 0;
}
classStudent[i].marks[j++] = m;
p = tail;
}
if (j < 4) {
printf("Expected 4 marks, but got %d.\n", j);
okay = 0;
}
}
Avg_Mark(&classStudent[i]);
}
return classStudent;
}
Please refrain from flushing buffers wihout reason. When a new-line character is written, stdout is flushed, so make it a rule to terminate all your strings with a new-line. New-lines at the beginning of strings instead of at the end are a sign of untidy output.
SOLUTION:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef struct { //struct decleration
char *name;
int marks[4];
float avg;
} student;
//functions decleration
student *Create_Class(int);
void Avg_Mark(student*);
void Print_One(student*);
void exStudents(student *s, int size);
int main() {
/*variable declerations*/
int i, size;
char line[80];
student *arr;
/*Input number of students*/
printf("\nEnter the number of students: \n");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &size);
/*Get name of students, marks, and calculate average above 85*/
arr = Create_Class(size);
exStudents(arr, size);
/*Free memory*/
for (i = 0; i < size; i++)
free(arr[i].name);
free(arr);
getch();
}
student *Create_Class(int size) { /*Get names of each student, and their 4 marks.*/
/*Variable declerations*/
int i, j;
char line[51];
student *classStudent;
/*Dynamic allocation to assign structure to every student*/
classStudent = (student*)malloc(size * sizeof(student));
/*Get name of students and their 4 marks*/
for (i = 0; i < size; i++) {
/*Variable decleration and dynamic allocation of 51 chars*/
classStudent[i].name = (char*)malloc(51 * sizeof(char));
int numOfmarks = 4;
int sizeOfName;
/*Input name of student*/
printf("Please enter your name: \n");
scanf("%s", classStudent[i].name);
/*Input marks of student*/
printf("Please enter 4 marks: ");
for (j = 0; j < numOfmarks; j++) {
scanf("%d", &classStudent[i].marks[j]);
}
/*Calculate average, and print averages of students above 85*/
Avg_Mark(&classStudent[i]);
}
return classStudent;
}
/*Calculate averages of students*/
void Avg_Mark(student *s) {
int i, numOfMarks = 4, sum = 0;
for (i = 0; i < numOfMarks; i++) {
sum += s->marks[i];
}
s->avg = (sum / 4.0);
}
/*Print average (if bigger than 85)*/
void Print_One(student *s) {
printf("The average of %s is %0.1f\n", s->name, s->avg);
}
/*Check whether the average is bigger than 85*/
void exStudents(student *s, int size) {
int flag = 1; //flag to check if there are any students with avg above 85
while (size > 0) {
if (s->avg > 85) {
Print_One(s); //Print the average
flag = 0; //We found atleast one student with avg > 85
}
s++; //Advance to next student
size--;
}
if (flag)
printf("\n There're no students with above 85 average.");
}
The problem in your code is that scanf does not consume the new-line returned by the user in:
scanf("%d", &size);
So when the program reaches:
fgets(classStudent[i].name,50,stdin);
the remaining new-line in stdin is received before the user can type anything.
A solution is to replace the initial scanf call by fgets and atoi calls.
char size_str[5];
fgets(size_str,5,stdin);
size = atoi(size_str);
A combination of fgets and sscanf also works also fine in general to first process user inputs and then convert it.
The variant with sscanf is:
char size_str[5];
fgets(size_str,5,stdin);
sscanf(size_str,"%d\n",&size);
Note that it might be safe to stop the program if the value entered is too large. Here we allow from 0 up to 999.
Note also that you have to do the same change some lines below.
instead of:
scanf("%d", &classStudent[i].marks[j]);
write:
char mark_str[5];
fgets(mark_str,5,stdin);
sscanf(mark_str,"%d\n",&classStudent[i].marks[j]);
Hope this helps.

Resources