Sublime Forum

Sublime dosent display output for complex C programs

#1

Hi,
Sublime Text doesn’t display any output whatsoever for a complex program, However it does compile it.
Code:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define N 5
struct node{
int data;
struct node *link;
};

int Top=-1;
typedef struct node Node;
Node *Head;

void Add_Begining(int ele){
	if(Top < N-1){
		Node *NewNode;

		NewNode = (Node *)malloc(sizeof(Node));
		NewNode->data = ele;
		NewNode->link = Head;
		Head = NewNode;
		Top++;
	}
	else{
		printf("\nStack Overflow!\n");
	}
}

int Del_Begining(){
	Node *CurrPtr;
	int ele;

	if(Head != NULL){
		CurrPtr = Head;
		ele = CurrPtr->data;
		Head = CurrPtr->link;
		Top--;
		free(CurrPtr);
		return(ele);
	}
	else{
		printf("\nStack Underflow!\n");
		return 0;
	}
}

void Display(){
	Node *CurrPtr;
	CurrPtr = Head;
	while(CurrPtr != NULL){
		printf("%d\t", CurrPtr->data);
		CurrPtr = CurrPtr->link;
	}
	printf("\n");
}


int main() {
    int ele,ch;
    printf("\nStack Operations\n\n");
    do{
    	printf("\n1. Push");
    	printf("\n2. Pop");
    	printf("\n3. Exit");
    	printf("\nEnter your choice:");
    	scanf("%d", &ch);
    	switch(ch){
    		case 1:{
    			printf("\nEnter Element:");
    			scanf("%d",&ele);
    			Add_Begining(ele);
    			printf("\n");
    			Display();
    			break;
    		}
    		case 2:{
    			ele = Del_Begining();
    			printf("\nDeleted element is: %d",ele);
    			printf("\n");
    			Display();
    			break;
    		}
    	}
    }while(ch != 3);
    return 0;
} 

This code compiles and runs in the terminal.
But when I hit ⌘B there is no output in sublime text even after waiting. However a compiled file pops up in the working directory which when executed by “./” in the terminal, runs.

Build system:

{
	"cmd" : ["gcc $file_name -o ${file_base_name} && chmod +x ${file_base_name} && ./${file_base_name}"],
	"selector" : "source.c",
	"shell": true,
	"working_dir" : "$file_path"
}

Please Note:
When I build a simple program in sublime text I get the output correctly!
Program like:

#include<stdio.h>
int main()
{
    printf("Hello\n");
    return 0;
}

Please Help
Thanks in advance.

0 Likes

#2

Your program is interactive, but Sublime doesn’t support that without more setup on your end. See the linked post below for more information. The short version is that you need to install a third party package and create your own build system, which also requires that you be familiar with how to compile and link a C program manually.

0 Likes

#3

Thank You!!

0 Likes