Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:23:02+00:00 2026-05-23T04:23:02+00:00

hello every one i am facing a strange problem i my code i am

  • 0

hello every one i am facing a strange problem i my code i am reading values from the file and file has rows and columns i am storing the second column in my array

but the problem i that when i first time copy in my position encryption[0] = token

i works well when i store at position encryption [1] my encryption [0] value over write with and become the same as encryption[1] the again at third loop encryption [0] ,encryption [1] become same as encryption [2] so in the end all values become the last sored value

here is my code kingly help me

#include<stdio.h>
#include <sys/stat.h>
#include<time.h>
#include<string.h>
void main()
{    
    FILE * f1 =  fopen("2.19.18.110_202.142.175.104.csv" , "r");
    if(f1==NULL)
    {
      printf("not open");    
    }
    char ch;
    int row =0;
    int col=0;
    while(ch!=EOF)
    {
        ch = fgetc(f1);
        if(ch=='\n')
            row++;
        if(ch==' ')
            col++;
    }
    fclose(f1);
    int b=0;
    int gg=0;
    //for( b=0;b<row;b++)
    char * encryption[row];
    char  payload[col*10];
    FILE * f2 =  fopen("2.19.18.110_202.142.175.104.csv" , "r");

    while( fgets ( payload, sizeof payload, f2)!=NULL)
    {
        int col1=0;
        printf("b= %d\t" , b);
        //  fgets ( payload, sizeof payload, f2);
        fputs(payload ,stdout);
        printf("\n\n");
        char *token;

        token = strtok(payload, " ");
        token = strtok(NULL, " ");  
        encryption[gg] = token;
        printf("token %s\n" ,token);   
        gg=gg+1;    

        printf("encryption %s\n" ,encryption[0]);    
        printf("encryption %s\n" ,encryption[1]);    
        printf("encryption %s\n" ,encryption[2]);    
        printf("encryption %s\n" ,encryption[3]);


        token = strtok(NULL, " "); 
        while ( token != NULL)
        {
          token = strtok(NULL, " ");
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:23:03+00:00Added an answer on May 23, 2026 at 4:23 am

    encryption[] is just an array of pointers – for each element you need to malloc() sufficient memory (strlen(token) + 1 bytes) and then use strcpy() to copy the string contents from token to encryption[gg].

    Change:

    token = strtok(NULL, " ");  
    encryption[gg] = token;
    

    to:

    token = strtok(NULL, " ");  
    encryption[gg] = malloc(strlen(token) + 1);
    strcpy(encryption[gg], token);
    

    Don’t forget to free() each element of encryption later when you’re done, otherwise you’ll leak memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello every one. I'm faced with a weird problem. My application has a simple
hello every one i want to pass the php array from the javascript function
Hello every one i have strange bug with dropdownlist on one of the pages!
Every Hello has a response. Second TTY will send a hello to the sender
hello every one i want to refresh my listview after adding or removing any
hi every body can some one help me with thi problem i have a
hello every one i have table view with one cell,and i make on this
Hello Everyone Iam trying to bulk insert data from .dat file(unloaded from sybase) in
Hello every one I want to send ajax call and on success I want
Hello every one, While taking back up of the database, i got the above

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.