C - Mixed Text File Data > To Different Arrays (Int and String)
I have just an ordinary "project.txt" file with this data:
Programming 10 3 4 5 4 3 2 4 5 2 3
Mathematics 8 3 3 4 5 3 2 2 3
Physics 6 3 4 5 3 4 5
Design 6 5 4 5 3 2 4
Logistics 8 3 4 5 3 1 1 2 3
Need to open this file, read and write all this data to arrays.
I need to somehow divide String and Integers from each other.
* NO NEED FOR IT RIGHT NOW, but later I will need to write text and numbers to different files. ***NO NEED TO DO THIS NOW*
Just need to do it with 2 different int and char arrays, but I am sitting for few hours and can't find normal explanation of how to divide this string from other things.
Here is my code, can anybody help me?
#include <stdio.h>
#include <stdlib.h>
int main(void)
FILE *fp;
fp = fopen("C:\Project\project.txt", "r");
char arrayWords[140];
int i;
if(fp == NULL)
printf("Can't Read The File!");
exit(0);
for (i = 0; i < 140; i++)
fscanf(fp, "%s,", &arrayWords[i]);
for (i = 0; i < 140; i++)
printf("Number is: %snn", &arrayWords[i]);
fclose(fp);
return 0;
This is the output I get, it is really confusing (Some part of it)...
Number is: P13454324523M833453223P6345345D6545324L834531123
Number is: 13454324523M833453223P6345345D6545324L834531123
Number is: 3454324523M833453223P6345345D6545324L834531123
Number is: 454324523M833453223P6345345D6545324L834531123
Number is: 54324523M833453223P6345345D6545324L834531123
Number is: 4324523M833453223P6345345D6545324L834531123
Number is: 324523M833453223P6345345D6545324L834531123
Number is: 24523M833453223P6345345D6545324L834531123
Number is: 4523M833453223P6345345D6545324L834531123
Number is: 523M833453223P6345345D6545324L834531123
Number is: 23M833453223P6345345D6545324L834531123
Number is: 3M833453223P6345345D6545324L834531123
Number is: M833453223P6345345D6545324L834531123
Number is: 833453223P6345345D6545324L834531123
Number is: 33453223P6345345D6545324L834531123
Number is: 3453223P6345345D6545324L834531123
Number is: 453223P6345345D6545324L834531123
Number is: 53223P6345345D6545324L834531123
Number is: 3223P6345345D6545324L834531123
Number is: 223P6345345D6545324L834531123
Number is: 23P6345345D6545324L834531123
Number is: 3P6345345D6545324L834531123
Number is: P6345345D6545324L834531123
Number is: 6345345D6545324L834531123
Number is: 345345D6545324L834531123
Number is: 45345D6545324L834531123
Number is: 5345D6545324L834531123
Number is: 345D6545324L834531123
Number is: 45D6545324L834531123
Number is: 5D6545324L834531123
Think problem is in pointers, but don't know, I am kind of a beginner and can't find any problems.
Thanks to everyone
c arrays string pointers
add a comment |
I have just an ordinary "project.txt" file with this data:
Programming 10 3 4 5 4 3 2 4 5 2 3
Mathematics 8 3 3 4 5 3 2 2 3
Physics 6 3 4 5 3 4 5
Design 6 5 4 5 3 2 4
Logistics 8 3 4 5 3 1 1 2 3
Need to open this file, read and write all this data to arrays.
I need to somehow divide String and Integers from each other.
* NO NEED FOR IT RIGHT NOW, but later I will need to write text and numbers to different files. ***NO NEED TO DO THIS NOW*
Just need to do it with 2 different int and char arrays, but I am sitting for few hours and can't find normal explanation of how to divide this string from other things.
Here is my code, can anybody help me?
#include <stdio.h>
#include <stdlib.h>
int main(void)
FILE *fp;
fp = fopen("C:\Project\project.txt", "r");
char arrayWords[140];
int i;
if(fp == NULL)
printf("Can't Read The File!");
exit(0);
for (i = 0; i < 140; i++)
fscanf(fp, "%s,", &arrayWords[i]);
for (i = 0; i < 140; i++)
printf("Number is: %snn", &arrayWords[i]);
fclose(fp);
return 0;
This is the output I get, it is really confusing (Some part of it)...
Number is: P13454324523M833453223P6345345D6545324L834531123
Number is: 13454324523M833453223P6345345D6545324L834531123
Number is: 3454324523M833453223P6345345D6545324L834531123
Number is: 454324523M833453223P6345345D6545324L834531123
Number is: 54324523M833453223P6345345D6545324L834531123
Number is: 4324523M833453223P6345345D6545324L834531123
Number is: 324523M833453223P6345345D6545324L834531123
Number is: 24523M833453223P6345345D6545324L834531123
Number is: 4523M833453223P6345345D6545324L834531123
Number is: 523M833453223P6345345D6545324L834531123
Number is: 23M833453223P6345345D6545324L834531123
Number is: 3M833453223P6345345D6545324L834531123
Number is: M833453223P6345345D6545324L834531123
Number is: 833453223P6345345D6545324L834531123
Number is: 33453223P6345345D6545324L834531123
Number is: 3453223P6345345D6545324L834531123
Number is: 453223P6345345D6545324L834531123
Number is: 53223P6345345D6545324L834531123
Number is: 3223P6345345D6545324L834531123
Number is: 223P6345345D6545324L834531123
Number is: 23P6345345D6545324L834531123
Number is: 3P6345345D6545324L834531123
Number is: P6345345D6545324L834531123
Number is: 6345345D6545324L834531123
Number is: 345345D6545324L834531123
Number is: 45345D6545324L834531123
Number is: 5345D6545324L834531123
Number is: 345D6545324L834531123
Number is: 45D6545324L834531123
Number is: 5D6545324L834531123
Think problem is in pointers, but don't know, I am kind of a beginner and can't find any problems.
Thanks to everyone
c arrays string pointers
The way you are scanning with%s, then storing into the character-arrayarrayWordsis not correct. I suggest you do some reading on C string handling, andprintf()/scanf()codes.
– Kingsley
Nov 14 '18 at 2:52
add a comment |
I have just an ordinary "project.txt" file with this data:
Programming 10 3 4 5 4 3 2 4 5 2 3
Mathematics 8 3 3 4 5 3 2 2 3
Physics 6 3 4 5 3 4 5
Design 6 5 4 5 3 2 4
Logistics 8 3 4 5 3 1 1 2 3
Need to open this file, read and write all this data to arrays.
I need to somehow divide String and Integers from each other.
* NO NEED FOR IT RIGHT NOW, but later I will need to write text and numbers to different files. ***NO NEED TO DO THIS NOW*
Just need to do it with 2 different int and char arrays, but I am sitting for few hours and can't find normal explanation of how to divide this string from other things.
Here is my code, can anybody help me?
#include <stdio.h>
#include <stdlib.h>
int main(void)
FILE *fp;
fp = fopen("C:\Project\project.txt", "r");
char arrayWords[140];
int i;
if(fp == NULL)
printf("Can't Read The File!");
exit(0);
for (i = 0; i < 140; i++)
fscanf(fp, "%s,", &arrayWords[i]);
for (i = 0; i < 140; i++)
printf("Number is: %snn", &arrayWords[i]);
fclose(fp);
return 0;
This is the output I get, it is really confusing (Some part of it)...
Number is: P13454324523M833453223P6345345D6545324L834531123
Number is: 13454324523M833453223P6345345D6545324L834531123
Number is: 3454324523M833453223P6345345D6545324L834531123
Number is: 454324523M833453223P6345345D6545324L834531123
Number is: 54324523M833453223P6345345D6545324L834531123
Number is: 4324523M833453223P6345345D6545324L834531123
Number is: 324523M833453223P6345345D6545324L834531123
Number is: 24523M833453223P6345345D6545324L834531123
Number is: 4523M833453223P6345345D6545324L834531123
Number is: 523M833453223P6345345D6545324L834531123
Number is: 23M833453223P6345345D6545324L834531123
Number is: 3M833453223P6345345D6545324L834531123
Number is: M833453223P6345345D6545324L834531123
Number is: 833453223P6345345D6545324L834531123
Number is: 33453223P6345345D6545324L834531123
Number is: 3453223P6345345D6545324L834531123
Number is: 453223P6345345D6545324L834531123
Number is: 53223P6345345D6545324L834531123
Number is: 3223P6345345D6545324L834531123
Number is: 223P6345345D6545324L834531123
Number is: 23P6345345D6545324L834531123
Number is: 3P6345345D6545324L834531123
Number is: P6345345D6545324L834531123
Number is: 6345345D6545324L834531123
Number is: 345345D6545324L834531123
Number is: 45345D6545324L834531123
Number is: 5345D6545324L834531123
Number is: 345D6545324L834531123
Number is: 45D6545324L834531123
Number is: 5D6545324L834531123
Think problem is in pointers, but don't know, I am kind of a beginner and can't find any problems.
Thanks to everyone
c arrays string pointers
I have just an ordinary "project.txt" file with this data:
Programming 10 3 4 5 4 3 2 4 5 2 3
Mathematics 8 3 3 4 5 3 2 2 3
Physics 6 3 4 5 3 4 5
Design 6 5 4 5 3 2 4
Logistics 8 3 4 5 3 1 1 2 3
Need to open this file, read and write all this data to arrays.
I need to somehow divide String and Integers from each other.
* NO NEED FOR IT RIGHT NOW, but later I will need to write text and numbers to different files. ***NO NEED TO DO THIS NOW*
Just need to do it with 2 different int and char arrays, but I am sitting for few hours and can't find normal explanation of how to divide this string from other things.
Here is my code, can anybody help me?
#include <stdio.h>
#include <stdlib.h>
int main(void)
FILE *fp;
fp = fopen("C:\Project\project.txt", "r");
char arrayWords[140];
int i;
if(fp == NULL)
printf("Can't Read The File!");
exit(0);
for (i = 0; i < 140; i++)
fscanf(fp, "%s,", &arrayWords[i]);
for (i = 0; i < 140; i++)
printf("Number is: %snn", &arrayWords[i]);
fclose(fp);
return 0;
This is the output I get, it is really confusing (Some part of it)...
Number is: P13454324523M833453223P6345345D6545324L834531123
Number is: 13454324523M833453223P6345345D6545324L834531123
Number is: 3454324523M833453223P6345345D6545324L834531123
Number is: 454324523M833453223P6345345D6545324L834531123
Number is: 54324523M833453223P6345345D6545324L834531123
Number is: 4324523M833453223P6345345D6545324L834531123
Number is: 324523M833453223P6345345D6545324L834531123
Number is: 24523M833453223P6345345D6545324L834531123
Number is: 4523M833453223P6345345D6545324L834531123
Number is: 523M833453223P6345345D6545324L834531123
Number is: 23M833453223P6345345D6545324L834531123
Number is: 3M833453223P6345345D6545324L834531123
Number is: M833453223P6345345D6545324L834531123
Number is: 833453223P6345345D6545324L834531123
Number is: 33453223P6345345D6545324L834531123
Number is: 3453223P6345345D6545324L834531123
Number is: 453223P6345345D6545324L834531123
Number is: 53223P6345345D6545324L834531123
Number is: 3223P6345345D6545324L834531123
Number is: 223P6345345D6545324L834531123
Number is: 23P6345345D6545324L834531123
Number is: 3P6345345D6545324L834531123
Number is: P6345345D6545324L834531123
Number is: 6345345D6545324L834531123
Number is: 345345D6545324L834531123
Number is: 45345D6545324L834531123
Number is: 5345D6545324L834531123
Number is: 345D6545324L834531123
Number is: 45D6545324L834531123
Number is: 5D6545324L834531123
Think problem is in pointers, but don't know, I am kind of a beginner and can't find any problems.
Thanks to everyone
c arrays string pointers
c arrays string pointers
asked Nov 13 '18 at 23:44
ლუკა ჩიტიშვილილუკა ჩიტიშვილი
17
17
The way you are scanning with%s, then storing into the character-arrayarrayWordsis not correct. I suggest you do some reading on C string handling, andprintf()/scanf()codes.
– Kingsley
Nov 14 '18 at 2:52
add a comment |
The way you are scanning with%s, then storing into the character-arrayarrayWordsis not correct. I suggest you do some reading on C string handling, andprintf()/scanf()codes.
– Kingsley
Nov 14 '18 at 2:52
The way you are scanning with
%s, then storing into the character-array arrayWords is not correct. I suggest you do some reading on C string handling, and printf()/scanf() codes.– Kingsley
Nov 14 '18 at 2:52
The way you are scanning with
%s, then storing into the character-array arrayWords is not correct. I suggest you do some reading on C string handling, and printf()/scanf() codes.– Kingsley
Nov 14 '18 at 2:52
add a comment |
1 Answer
1
active
oldest
votes
It's easy to parse these lists of space-separated numbers using the strtol() function. This is a good solution because it handily sets a pointer to the next block of whitespace/non-number after the number it just converted. If there's no number to convert, it just sends back the original pointer. So the code tests for this to know when it's complete.
EDIT: Updated to handle name too.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
char *number_str = "SomeWords 19 9 6 2 22 1 0 -4";
char *ptr;
char *next_number;
int numbers[1000];
int number_count = 0;
char name[100];
next_number = number_str;
// Copy off the name
ptr = strchr(number_str, ' ');
if (ptr != NULL)
strncpy(name, number_str, ptr-number_str); // TODO - check bounds of name
name[ptr-number_str] = '';
// Point to the first number
next_number = ptr+1;
printf("Stored name [%s]n", name);
// Then parse all the numbers
do
ptr = next_number;
long num = strtol(ptr, &next_number, 10);
if (ptr != next_number) // found one
numbers[number_count] = (int)num;
printf("Stored %3d into numbers[%d]n", numbers[number_count], number_count);
number_count += 1;
while(ptr != next_number);
return 0;
Outputs:
Stored name [SomeWords]
Stored 19 into numbers[0]
Stored 9 into numbers[1]
Stored 6 into numbers[2]
Stored 2 into numbers[3]
Stored 22 into numbers[4]
Stored 1 into numbers[5]
Stored 0 into numbers[6]
Stored -4 into numbers[7]
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Usefgets()to read a line from the file into achar *buffer.
– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291110%2fc-mixed-text-file-data-to-different-arrays-int-and-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's easy to parse these lists of space-separated numbers using the strtol() function. This is a good solution because it handily sets a pointer to the next block of whitespace/non-number after the number it just converted. If there's no number to convert, it just sends back the original pointer. So the code tests for this to know when it's complete.
EDIT: Updated to handle name too.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
char *number_str = "SomeWords 19 9 6 2 22 1 0 -4";
char *ptr;
char *next_number;
int numbers[1000];
int number_count = 0;
char name[100];
next_number = number_str;
// Copy off the name
ptr = strchr(number_str, ' ');
if (ptr != NULL)
strncpy(name, number_str, ptr-number_str); // TODO - check bounds of name
name[ptr-number_str] = '';
// Point to the first number
next_number = ptr+1;
printf("Stored name [%s]n", name);
// Then parse all the numbers
do
ptr = next_number;
long num = strtol(ptr, &next_number, 10);
if (ptr != next_number) // found one
numbers[number_count] = (int)num;
printf("Stored %3d into numbers[%d]n", numbers[number_count], number_count);
number_count += 1;
while(ptr != next_number);
return 0;
Outputs:
Stored name [SomeWords]
Stored 19 into numbers[0]
Stored 9 into numbers[1]
Stored 6 into numbers[2]
Stored 2 into numbers[3]
Stored 22 into numbers[4]
Stored 1 into numbers[5]
Stored 0 into numbers[6]
Stored -4 into numbers[7]
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Usefgets()to read a line from the file into achar *buffer.
– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
add a comment |
It's easy to parse these lists of space-separated numbers using the strtol() function. This is a good solution because it handily sets a pointer to the next block of whitespace/non-number after the number it just converted. If there's no number to convert, it just sends back the original pointer. So the code tests for this to know when it's complete.
EDIT: Updated to handle name too.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
char *number_str = "SomeWords 19 9 6 2 22 1 0 -4";
char *ptr;
char *next_number;
int numbers[1000];
int number_count = 0;
char name[100];
next_number = number_str;
// Copy off the name
ptr = strchr(number_str, ' ');
if (ptr != NULL)
strncpy(name, number_str, ptr-number_str); // TODO - check bounds of name
name[ptr-number_str] = '';
// Point to the first number
next_number = ptr+1;
printf("Stored name [%s]n", name);
// Then parse all the numbers
do
ptr = next_number;
long num = strtol(ptr, &next_number, 10);
if (ptr != next_number) // found one
numbers[number_count] = (int)num;
printf("Stored %3d into numbers[%d]n", numbers[number_count], number_count);
number_count += 1;
while(ptr != next_number);
return 0;
Outputs:
Stored name [SomeWords]
Stored 19 into numbers[0]
Stored 9 into numbers[1]
Stored 6 into numbers[2]
Stored 2 into numbers[3]
Stored 22 into numbers[4]
Stored 1 into numbers[5]
Stored 0 into numbers[6]
Stored -4 into numbers[7]
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Usefgets()to read a line from the file into achar *buffer.
– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
add a comment |
It's easy to parse these lists of space-separated numbers using the strtol() function. This is a good solution because it handily sets a pointer to the next block of whitespace/non-number after the number it just converted. If there's no number to convert, it just sends back the original pointer. So the code tests for this to know when it's complete.
EDIT: Updated to handle name too.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
char *number_str = "SomeWords 19 9 6 2 22 1 0 -4";
char *ptr;
char *next_number;
int numbers[1000];
int number_count = 0;
char name[100];
next_number = number_str;
// Copy off the name
ptr = strchr(number_str, ' ');
if (ptr != NULL)
strncpy(name, number_str, ptr-number_str); // TODO - check bounds of name
name[ptr-number_str] = '';
// Point to the first number
next_number = ptr+1;
printf("Stored name [%s]n", name);
// Then parse all the numbers
do
ptr = next_number;
long num = strtol(ptr, &next_number, 10);
if (ptr != next_number) // found one
numbers[number_count] = (int)num;
printf("Stored %3d into numbers[%d]n", numbers[number_count], number_count);
number_count += 1;
while(ptr != next_number);
return 0;
Outputs:
Stored name [SomeWords]
Stored 19 into numbers[0]
Stored 9 into numbers[1]
Stored 6 into numbers[2]
Stored 2 into numbers[3]
Stored 22 into numbers[4]
Stored 1 into numbers[5]
Stored 0 into numbers[6]
Stored -4 into numbers[7]
It's easy to parse these lists of space-separated numbers using the strtol() function. This is a good solution because it handily sets a pointer to the next block of whitespace/non-number after the number it just converted. If there's no number to convert, it just sends back the original pointer. So the code tests for this to know when it's complete.
EDIT: Updated to handle name too.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
char *number_str = "SomeWords 19 9 6 2 22 1 0 -4";
char *ptr;
char *next_number;
int numbers[1000];
int number_count = 0;
char name[100];
next_number = number_str;
// Copy off the name
ptr = strchr(number_str, ' ');
if (ptr != NULL)
strncpy(name, number_str, ptr-number_str); // TODO - check bounds of name
name[ptr-number_str] = '';
// Point to the first number
next_number = ptr+1;
printf("Stored name [%s]n", name);
// Then parse all the numbers
do
ptr = next_number;
long num = strtol(ptr, &next_number, 10);
if (ptr != next_number) // found one
numbers[number_count] = (int)num;
printf("Stored %3d into numbers[%d]n", numbers[number_count], number_count);
number_count += 1;
while(ptr != next_number);
return 0;
Outputs:
Stored name [SomeWords]
Stored 19 into numbers[0]
Stored 9 into numbers[1]
Stored 6 into numbers[2]
Stored 2 into numbers[3]
Stored 22 into numbers[4]
Stored 1 into numbers[5]
Stored 0 into numbers[6]
Stored -4 into numbers[7]
edited Nov 14 '18 at 2:48
answered Nov 14 '18 at 1:17
KingsleyKingsley
2,97021325
2,97021325
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Usefgets()to read a line from the file into achar *buffer.
– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
add a comment |
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Usefgets()to read a line from the file into achar *buffer.
– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
I don't have problems with int, I have lines which begin with string and continues with numbers, I can use char to output whole lines, but I can't take that first string and put it in one array and later take those numbers on the same line and put them in another array, that is my problem
– ლუკა ჩიტიშვილი
Nov 14 '18 at 2:27
Use
fgets() to read a line from the file into a char *buffer.– Kingsley
Nov 14 '18 at 2:55
Use
fgets() to read a line from the file into a char *buffer.– Kingsley
Nov 14 '18 at 2:55
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
Yep, now I can somehow focus on one line, but still there is a problem. I still have mixed string, with letters and numbers, it starts with word PROGRAMMING and continues with few numbers, How can I take only this programming and add it to string array ?
– ლუკა ჩიტიშვილი
Nov 14 '18 at 3:08
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
@ლუკაჩიტიშვილი - did you read the changes I made above?
– Kingsley
Nov 14 '18 at 3:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291110%2fc-mixed-text-file-data-to-different-arrays-int-and-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The way you are scanning with
%s, then storing into the character-arrayarrayWordsis not correct. I suggest you do some reading on C string handling, andprintf()/scanf()codes.– Kingsley
Nov 14 '18 at 2:52