I post this on C too... Well, my program read all lines from (plain.txt) and save temporary every read strings line by line into another text called(all.txt), i made the md5sum hash on each line separately of (all.txt) and saving this hashes on calculating.txt... then delete the all.txt and calculating.txt, creating a new copy of calculating (hashes.txt)

I want to do this process one-way only with the command
with array or something without using files.

echo -n (read string line) | openssl md5
plain.txt
a
b
c
d
e
f
g
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define Plain "plain.txt" 

int main(){

	FILE *fp;
	FILE *read_fp;
	FILE *read_tmp;
	int chars_read;
	char hash[1024] = "openssl dgst -md5 all.txt >> calculating.txt";
	char buffer[1024];
	char line[128];

	if ((fp = fopen(Plain, "r")) == NULL){
    perror (Plain);
    return (EXIT_FAILURE);
       }

	printf("\tCreating Hash Table. Please wait....\n" );

	while(!feof(fp))
	{
		fscanf(fp,"%s", &line);

		read_tmp = fopen("all.txt","w+");
		fprintf(read_tmp,"%s", &line);
		fclose(read_tmp); 


		read_fp = popen(hash,"r");
		if (read_fp != NULL) {
			while ((chars_read = fread(buffer, sizeof(char), 1024 , read_fp)) > 0 ){
			}
			pclose(read_fp);
		}
	}

	fclose(fp);
	system("sed '$d' calculating.txt > hashes.txt");
	system("rm all.txt");
	system("rm calculating.txt");
	printf("Hashes Calculated Successfully... [OK!]\n");

	return 0;
}

nvm! delete this thread! i solved it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.